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:

... grep {print STDERR "\$_: $_\n"; $_ eq $arrList[2]} @list_match
So whatever the problem is, it is not a collision of $_.

btw: I would use a variable when looping through a file, instead of using $_:

while(my $line = <INPUT>){ chomp($line); ...
Then you don't have to worry about $_ getting clobbered by something else and you code becomes more readable.

Replies are listed 'Best First'.
Re^2: Grep inside the while Loop
by snape (Pilgrim) on Oct 20, 2010 at 23:27 UTC

    Yeah you are right. I made a programming mistake due to which my grep commend was not working. It was not a questions of $_ collision. Thanks for the enlightening me.