stanley82 has asked for the wisdom of the Perl Monks concerning the following question:
oops I've maybe got the post right this time I'm a bit messed up with $_ The code below failed to work til I was specific as what to write. In the IF block "print NEW;" worked but in the ELSE block it failed, but once I explicitly used $fields[0] it was fine. $_ has me a bit frustrated with loops in loops as to which $_ I'm using. Regards Ian.
while (<UNMATCHED>) { @fields = split(/:/, $_); $wd = substr($fields[0], 0, 1); if($wd eq "/") { my $rtn = search ($fields[0], UNUSED); #Returns 1 i +f #fields[0] is found in UNUSED. print "Return is = $rtn \n"; if($rtn == 1) { print "Writing to CHANGED. \n"; print CHANGED "$fields[0] \n"; # print NEW; #This works in IF but n +ot in ELSE ? } else { print "Writing to NEW \n"; print NEW "$fields[0] \n"; #This works # print NEW; #This does not } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $_ confusion with loops in loops
by AnomalousMonk (Archbishop) on Mar 06, 2019 at 20:30 UTC | |
|
Re: $_ confusion with loops in loops
by AnomalousMonk (Archbishop) on Mar 06, 2019 at 20:00 UTC | |
|
Re: $_ confusion with loops in loops
by stanley82 (Novice) on Mar 06, 2019 at 21:37 UTC |