in reply to Re^2: Unable to declare local variable with "use strict".
in thread Unable to declare local variable with "use strict".

Strict makes you declare your variables. Local does not declare a variable...
it makes a backup copy of an existing global variable, and that global is still global.

my declares a local variable. my is what you want to use.

Replies are listed 'Best First'.
Re^4: Unable to declare local variable with "use strict".
by JavaFan (Canon) on Mar 27, 2010 at 00:03 UTC
    Strict makes you declare your variables.
    Wrong.

    Strict only prevents unqualified variables to default to package variables, by throwing an exception. Declaring a variable with my is only one of the ways to satisfy strict. But you may introduce a variable using local, our or use vars. Or use a fully qualified name.

      > But you may introduce a variable using local,

      no you can't, local doesn't declare!

      lanx@nc10-ubuntu:~$ perl -e 'use strict; local $x=4; print $x' Global symbol "$x" requires explicit package name at -e line 1. Global symbol "$x" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. lanx@nc10-ubuntu:~$ perl -e 'use strict; our $x=4; print $x' 4lanx@nc10-ubuntu:~$

      Cheers Rolf