in reply to $_ confusion with loops in loops
while (<UNMATCHED>) { ... }
It's a little difficult for me to understand just what you expect from the posted code and what "failed to work," but one thing I suspect is that you may be expecting the value of $_ set in the while-loop quoted above (a block read from a file) to be unchanged throughout the while-loop.
But while-loops do not "topicalize" the value of $_ as for-loops do. I also see that there is a
my $rtn = search ($fields[0], UNUSED);
statement in the quoted while-loop that seems to be searching a file with the handle UNUSED. If this search uses another
while (<UNUSED>) { ... }
while-loop structure, the value of $_ will be changed and will not be restored upon return to the scope of the posted code unless $_ was properly local-ized within the search() function.
I think my advice would be to use lexical variables as the loop variable and in other cases within the block:
See my. Save your worries about $_ for for-loops, map and grep built-ins, etc.while (my $record = <UNMATCHED>) { my @fields = split(/:/, $record); ... }
Give a man a fish: <%-{-{-{-<
|
|---|