Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: search position is getting reset after 'local'

by reasonablekeith (Deacon)
on Jun 12, 2006 at 13:34 UTC ( [id://554812]=note: print w/replies, xml ) Need Help??


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.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://554812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-29 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found