in reply to $_ confusion with loops in loops

Please review your <code> tag - the formatting in your node is messed up.

It is likely that when your sub "search" returns a value that is not ==1, it sets $_.

my $rtn = search ($fields[0], UNUSED);

                As a computer, I find your faith in technology amusing.

Replies are listed 'Best First'.
Re^2: $_ confusion with loops in loops
by BillKSmith (Monsignor) on Mar 06, 2019 at 20:15 UTC
    You can fix this problem by declaring $_ with 'local' in the search routine.
    sub search { local $_; ... }

    The previous value of $_ is restored when search returns ($_ goes out of scope).

    Bill

      You could do that, or you could use a lexical variable with a sensible name that not only completely avoids the issue, but also makes the code easier to read.

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond