in reply to Grep inside the while Loop
I think it is assuming "$_" as the entire current line of the file.No. At least in recent Perls (I am using 5.12) the $_ used in grep is localized and contains in your example the current element of the array - your code is ok here.
You can easily verify that yourself if you add a trace, e.g:
So whatever the problem is, it is not a collision of $_.... grep {print STDERR "\$_: $_\n"; $_ eq $arrList[2]} @list_match
btw: I would use a variable when looping through a file, instead of using $_:
Then you don't have to worry about $_ getting clobbered by something else and you code becomes more readable.while(my $line = <INPUT>){ chomp($line); ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Grep inside the while Loop
by snape (Pilgrim) on Oct 20, 2010 at 23:27 UTC |