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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.