in reply to Difference b/w my and local var?

They don't do the same thing at all.

my creates a new variable that's only visible to the scope in which it's defined.

local doesn't create a variable. local temporary saves the variable and restores it at the end of the scope. Unlike my, local does not limit the scope of the variable. If the variable being localized is a package variable (and it usually is), it's still globally accessible after being localized.

Always use my whenever possible.

Replies are listed 'Best First'.
Re^2: Difference b/w my and local var?
by ig (Vicar) on Mar 11, 2009 at 23:34 UTC

    For clarification of what "doesn't create a variable" means, the following examples might be interesting/surprising (they were for me when I first realized what was happening).

    This is rather OT to the OP's question and also rather esoteric. If one doesn't use aliases or tied variables or directly manipulate symbol tables (stashes) then the distinction/clarification may not be helpful/relevant.