in reply to Re: difference between my and local
in thread difference between my and local

I get: Can't localize lexical variable $var at ./a.pl line 11
What exactly does our do ?

Your example shows that you can only use local on global variables...
So why use my anyway ?

Luca

Replies are listed 'Best First'.
Re^3: difference between my and local
by Perl Mouse (Chaplain) on Nov 15, 2005 at 13:19 UTC
    our creates a lexical scoped name for a global variable.

    Your example shows that you can only use local on global variables
    Well, it more on anything that isn't a lexical variable. You can localize array elements for instance, even if the array itself is a lexical variable.
    So why use my anyway
    Because my creates lexically scoped variables. Variables that aren't visible outside of the block that declares them. local creates temporary values, which are only reset if a block gets exited.

    The right question should be "why use local?".

    Perl --((8:>*
Re^3: difference between my and local
by davorg (Chancellor) on Nov 15, 2005 at 13:17 UTC
    What exactly does our do ?

    See the documentation.

    So why use my anyway ?

    Because scoped variables are easier to handle than global variables.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg