in reply to Re: $_ confusion with loops in loops
in thread $_ confusion with loops in loops

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

Replies are listed 'Best First'.
Re^3: $_ confusion with loops in loops
by GrandFather (Saint) on Mar 07, 2019 at 00:48 UTC

    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