|Problems? Is your data what you think it is?|
Grep inside the while Loopby snape (Pilgrim)
|on Oct 20, 2010 at 22:49 UTC||Need Help??|
snape has asked for the
wisdom of the Perl Monks concerning the following question:
It is more of a conceptual question rather than a logic question. I have 2 while loops in my program below. The first while loop is used to store the set of words in an array after opening the first file. The second while loop is used to find if there is a match between the the words in the array with the words in the the 3rd column of second file.
I used grep inside the while loop for checking the "matched text". My code is as follows:
Now if I use the above code then it doesn't find the "match word". I think it is assuming "$_" as the entire current line of the file. My question is why doesn't it assume as the current index of the array @list_match. If you use the same convention of grep in comparing the 2 arrays then it will work. For example:
I know there is another way of using grep like
but I would like to know why the prior grep syntax in the while loop doesn't work. Thanks a lot.
UPDATE : I am sorry, my code is correct and there is no collision of $_. The above code works. I did a mistake while I was coding before. Sorry for the inconvenience. Thanks