On 5/6/05, macromedia wrote: > Hello, > > I have the following find/grep line running just fine from a telnet > prompt on the server. I'm trying to include this line into a web app > using CFEXECUTE (ColdFusion) but can't get it to work. I know that a > compiled perl script would work since I'm already using some previously > written ones. > > How could I do the following in Perl? I'm searing the directory > d:\mywork and all sub-directories within for all the files with a .txt > file extension and within those files for the match of "000;" > > find D:\mywork -name '*.txt' -exec grep '000;' '{}' \; -print" >
You can use the File::Find module to do the same. I wasn't sure if your above command also prints the matching lines or just the file names, I assumed you also get a printout from grep. So something like this (untested!) should work: ########### begin code use strict; use warnings; use File::Find; find(\&wanted, "D:\mywork"); sub wanted { if (m/\.txt$/) { open(IN,$File::Find::name) or die "Couldn't open $File::Find::name for reading: $!\n"; while(defined(my $line=<IN>)) { if ($line =~ m/000;/) { print "$File::Find::name : $line"; } } close(IN) or die "Couldn't close $File::Find::name after reading: $!\n"; } } ########### end code Read the documentation of File::Find for more details about using this module. You can read from your locally installed Perl documentation (i.e. "perldoc File::Find from the command line), or online at: http://perldoc.perl.org/File/Find.html HTH, -- Offer Kaye -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>