in reply to search position is getting reset after 'local'

so another reason to "use strict;" then?

I can't see how you'd reproduce this bug with it switched on.

Update: I just _knew_ someone would see this post as a challenge. I meant that, if one were using strict and declaring lexically scoped varaible, you probably wouldn't hit this, as you well know Corion.

Anyway, I thought "use vars;" was obsolete, so I'm not sure it counts? Any other offers? :)

---
my name's not Keith, and I'm not reasonable.
  • Comment on Re: search position is getting reset after 'local'

Replies are listed 'Best First'.
Re^2: search position is getting reset after 'local'
by Corion (Patriarch) on Jun 12, 2006 at 13:36 UTC
    #!/usr/bin/perl -w use strict; use vars qw($x); $x = "123 56"; $x =~ / /g; print "$x, ", pos($x), "\n"; { local $x } print "$x, ", pos($x), "\n";
Re^2: search position is getting reset after 'local'
by ikegami (Patriarch) on Jun 12, 2006 at 15:22 UTC

    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).