Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Are global variables "bad"?

by Anonymous Monk
on Apr 21, 2009 at 20:34 UTC ( [id://759107]=note: print w/replies, xml ) Need Help??


in reply to Re: Are global variables "bad"?
in thread Are global variables "bad"?

"Perl 1, 2, 3 and 4 didn't have lexical variables. Or name spaces. All variables where global"
Where did the local statement fit into this absolutist scheme?

Replies are listed 'Best First'.
Re^3: Are global variables "bad"?
by Corion (Patriarch) on Apr 21, 2009 at 20:59 UTC
      local only works on global variables.
      Not true. It's not even true if you meant "package" where you wrote "global".
      $ perl -wE 'my @a = (1, 2, 3); {local $a[1] = 7; say "@a";} say "@a"' 1 7 3 1 2 3
Re^3: Are global variables "bad"?
by JavaFan (Canon) on Apr 21, 2009 at 21:02 UTC
    local() essentially replaces the current variable (package variable - or aggregate element) with another variable, until the runtime exits the scope the local() is in.

    If no magic is involved, it may be easier to think of it as temporary replacing the value.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found