Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^8: type glob

by JadeNB (Chaplain)
on Nov 18, 2009 at 20:29 UTC ( #808018=note: print w/replies, xml ) Need Help??


in reply to Re^7: type glob
in thread type glob

local doesn't create variables. It just backs up the value of the variable and restores it later.

I know *. Certainly there's an internal difference; but it seems to me that the casual user is not likely to encounter much difference between

our $x; CODE INVOLVING OUTER $x { local $x; CODE INVOLVING INNER $x }
and
my $x; CODE INVOLVING OUTER $x { my $x; CODE INVOLVING INNER $x }
That's by no means to say that there is no difference—indeed,
our $x; my $y; sub twiddle { $x = $y = 'twiddled' } { local $x = 'local?'; my $y = 'local!'; twiddle; say $x, ', ', $y; }
shows that there is—just that one's not likely to see it in casual use.

* Ah, but re-reading shows that I didn't seem to understand: I said something about having two variables with the same name, when really the localised $x is the same variable as the original one, just with a ‘temporary’ value. Is that misstatement on my part what you were correcting?

Replies are listed 'Best First'.
Re^9: type glob
by ikegami (Pope) on Nov 18, 2009 at 22:55 UTC

    just that one's not likely to see it in casual use.

    If a child scope has a variable with the same name as its parent scope, it would look like

    my $x; sub foo { ... $x ... } sub bar { ... my $x ... }

    What you said boils down to saying bar is unlikely to call foo, and I don't see how that is true.

    I it is unlikely that the same var name is used at two levels in a working program, but that's something else.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2021-05-10 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (108 votes). Check out past polls.

    Notices?