On Wed, 2 Mar 2011, Matt wrote: > > The easiest way in my opinion is to use the 'grep' function like this: > > > > my $searchstring="whatever"; > > open CFG, '<', $_file || die("could not open file: $_file!"); > > my @data=<CFG>; > > close CFG; > > if ( grep /$searchstring/i, @data ) { > > print "$searchstring found\n"; > > } > > > > This sorta worked. Needed a minor change. > > > unless ( grep /$searchstring/i, @data ) { > > print "$searchstring not found\n"; > > Thanks. >
My apologies if I'm beating a dead horse here, but I'm new to Perl and thought of a slightly different approach: my $searchrx = qr/whatever/; # or q/whatever/ if you don't need regexp @ARGV or die qq/you didn't specify a filename\n/; open FH, q/</, shift @ARGV or die qq/file open error: $!/; $_ = join q//, <FH>; close FH; if ( ! m/$searchrx/s ) { print qq/pattern not found\n/; # do something } I'm not sure which is more "Perlish", but I hear "TMTOWTDI" is supposed to be valued, too. I welcome any criticism. Brian
-- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/