stanley82 has asked for the wisdom of the Perl Monks concerning the following question:
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 } } }
2019-03-07 Athanasius fixed closing code tag
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $_ confusion with loops in loops
by NetWallah (Canon) on Mar 06, 2019 at 19:56 UTC | |
by BillKSmith (Monsignor) on Mar 06, 2019 at 20:15 UTC | |
by GrandFather (Saint) on Mar 07, 2019 at 00:48 UTC |