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.