Pam Derks wrote: > > Hi, > > Newbie here...I'm trying to find the string "Take our survey" in all the files that >match this pattern, traversing multiple directories. When I run it I get no >filenames. I'm positive the string exists. Any ideas as to what I'm doing wrong. > > Thanks for any help, Pam > > Here's what I've got..... > > #!/usr/bin/perl > #process all files in directory www/htdocs > > use File::Find; > @ARGV = qw(/dept/unxmkt/www/htdocs) unless @ARGV; > find(\&find_it, @ARGV); > > sub find_it{ > foreach $_(@ARGV){ > while (<>){ > if ($_=~ /Take our survey/){ > print ("$_\n"); > } > } > } > > } #end find_it
Here is one way to do it: #!/usr/bin/perl -w use strict; use File::Find; @ARGV = qw(/dept/unxmkt/www/htdocs) unless @ARGV; find( sub { return unless -f; # only want files if ( open FILE, $_ ) { while ( <FILE> ) { if ( index( $_, 'Take our survey' ) >= 0 ) { print "$_\n"; return; } } } }, @ARGV ); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]