Jason Wertz on Wed, 18 Dec 2002 10:30:32 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Perl and a large concatination


One of my favorite Perl books is O'Reilly's Perl Cookbook. On page 322 it has code for "processing all files in a directory recursively." All you would have to do is use a regex to determine whether to process a given file or skip it. The code is really simple too...here's the basic example but you'll need to read the Perldocs on File::Find to get all of the variable names (such as $File::Find::name which contains the full path of the current file bein processed...$_ contains just the file name and $File::Find::dir is the path relative to the starting directory). In the following code example @DIRLIST is a list of directories you want recursively searched.

use File::Find;

sub process_file {
       #process your files here
}

find(\&process_file, @DIRLIST);

Hope this helps.

Jason Wertz
Senior Technology Specialist / WebMaster
Delaware County Community College
ph: 610-325-2771
fax: 610-325-2820
http://learn.dccc.edu/~jason




>>> brmolnar@exchange.ursinus.edu 12/17/02 10:28PM >>>
Ok, here is my problem, I have been trying for a while to write a script
that runs and based on the current directory, gets a list of all
subdirectories and trys to open a file in each one. 

I know the file name will the 'srquote' so, that isn't a puzzle. I had it
working with several files as long as they were all in the same directory,
but, when I try to open them up in different directories, nothing works.
Here is my single directory version, any ideas anyone? 

thanks 

-brad

#!/usr/sbin/perl

@list=qx{ls};

open(OUTF,">>quote.txt");

flock(OUTF,2);

foreach $entry (@list) {

        $entry =~ tr/'\n'/'\0'/;

        open(INF, $entry) or die("Couldn't open file: $!");


        seek(OUTF,0,2);


              foreach $line (@a){
                    print OUTF "$line";
                    print "$line should be here";
              }


         close(INF);
}

close (OUTF);

print "all done, I think\n\n";
_________________________________________________________________________
Philadelphia Linux Users Group        --       http://www.phillylinux.org 
Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce 
General Discussion  --   http://lists.netisland.net/mailman/listinfo/plug


_________________________________________________________________________
Philadelphia Linux Users Group        --       http://www.phillylinux.org
Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce
General Discussion  --   http://lists.netisland.net/mailman/listinfo/plug