in reply to Re: When does while set $_ ?
in thread When does while set $_ ?


You could localise $_ as follows:
while (local $_ = match('a')) { print "- $_\n"; }

However, it would be better to use grep() instead of your match() function. Then all of your code could be replaced with the following line: ;-)     print "- $_\n" for grep {/a/} @data;

--
John.

Replies are listed 'Best First'.
Re: When does while set $_ ?
by crenz (Priest) on Aug 01, 2002 at 10:34 UTC

    Thanks. Unfortunately, using grep() is not an option -- the original match() could involve multiple m// or a SQL query, depending on the data interface selected ;-).

    But I wonder how four grep()'s compare to four m//'s in a foreach loop... I guess the latter approach still wins, because the array needs to be traversed only once.