in reply to Re: Whether to use local()
in thread Whether to use local()

local only works on global variables

my %foo; $foo{bar} = " odd then?\n"; { local $foo{bar} ="Isn't this"; print $foo{bar}; } print $foo{bar};
:-P

Replies are listed 'Best First'.
Re: Re (tilly) 2: Whether to use local()
by shotgunefx (Parson) on Mar 16, 2002 at 02:05 UTC
    I know about local on hash elements and array elements but thought it would complicate the explanation for him. Just like I omitted PadWalker from the explanation of accessing lexicals. Point taken though. Was local on hash/array elements added as a hack for signal handlers? It seems the only real use that I've seen. Or is it used internally when you localize a package var in the symbol table seeing a package is in a sense a hash?

    -Lee

    "To be civilized is to deny one's nature."
      Was local on hash/array elements added as a hack for signal handlers?

      local was added to perl when there were only global variables as a hack for providing a means of creating "local" variables. There are other uses for it though, but that is better said here: Seven Useful Uses of local

        I guess what I find odd about it working on pieces of arrays and hashes is why bother? I mean if it can do a chunk of a lexical hash, why not a whole hash? I can't imagine why the half implementation. I'm sure there was a good reason, but I can't imagine what it is.

        -Lee

        "To be civilized is to deny one's nature."