in reply to Re: search position is getting reset after 'local'
in thread search position is getting reset after 'local'
Re your update, here's a version that doesn't use use vars:
#!/usr/bin/perl -w use strict; our $x = "123 56"; $x =~ / /g; print "$x, ", pos($x), "\n"; { local $x } print "$x, ", pos($x), "\n";
I think you meant, "another reason to avoid using package variables".
By the way, I don't see how you got it to work with strict on. It doesn't work if you keep $x as a package variable, and local $x doesn't work if you changed $x into a lexical (i.e. used my $x).
|
---|