in reply to searching a file
If you don't need $str in your code, write something like this:my @list = qw(value1 value2); unless (open (FILE, $filename)){ die("Error in opening $filename: $!\n"); } # if else { while (<FILE>){ chomp($_); # split up to maximal "two columns" by whitespaces my ($str, $val) = split(/\s+/, $_, 2); # search @list for $val if ( grep { $val eq $_ } @list ){ print "$val found\n"; } } # while close (FILE); } # else
... while (<FILE>){ chomp($_); # split up to maximal "two columns" by whitespaces my ($val) = ( split(/\s+/, $_, 2) )[1]; # search @list for $val if ( grep { $val eq $_ } @list ){ print "$val found\n"; } } # while } # else
I haven't tested these codes.
Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: searching a file
by tachyon (Chancellor) on Mar 19, 2002 at 18:43 UTC |