http://www.perlmonks.org?node_id=969448


in reply to Re^5: Noob could use advice on simplification & optimization
in thread Noob could use advice on simplification & optimization

'my' variables are lexical to the enclosing block. Here, since the variables are declared in the MAIN package, outside of any block, they are global, or visible to all all blocks within the package MAIN.

Almost. They have file scope, they're global to the file. See Lexical scoping like a fox,

$ cat foo1.pl my $foo = qq{i'm in main too ${\__FILE__}\n}; sub foo1 { print $foo; } $ cat foo2.pl my $foo = qq{i'm in main too ${\__FILE__}\n}; sub foo2 { print $foo; } $ perl -e " require $_ for qw/ foo1.pl foo2.pl /; foo1(); foo2(); " i'm in main too foo1.pl i'm in main too foo2.pl

Replies are listed 'Best First'.
Re^7: Noob could use advice on simplification & optimization
by bgreg (Initiate) on May 09, 2012 at 20:20 UTC
    Got it. Thanks all!