develooper Front page | perl.perl5.porters | Postings from November 1999

Regex match variables, threads, and recursion

Dan Sugalski
November 5, 1999 09:52
Regex match variables, threads, and recursion
Message ID:
A couple of days ago someone (mjd?) was wondering if the problem that
threads have with the regex match variables (where the regex variables are
tied to pieces of the code and reflect the last thread that executed it)
occurred with non-threaded code too. Just for chuckles, I decided to try it
this afternoon and, as expected, the problem can be duplicated with a
non-threaded perl build. Witness:

	$search_string = "123abc";

	sub foo {
	    $again = shift;
	    $search_string =~ /(\d+)(\w+)/;
	    print "$1 $2\n";
	    return unless $again;
	    $search_string = "456def";
	    print "$1 $2\n";



123 abc
456 def
456 def

I don't recall seeing this documented anywhere, though it very well might be.

Given that this is going to be fixed in one way or another for threaded
perl, do we want to go all the way and fix it so non-threaded perl does
lexical scoping for the match variables too?


----------------------------------------"it's like this"-------------------
Dan Sugalski                            even samurai                           have teddy bears and even
                                        teddy bears get drunk Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About