Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Syntactic Confectionery Delight
 
PerlMonks  

Re^5: Noob could use advice on simplification & optimization

by thundergnat (Deacon)
on May 08, 2012 at 12:48 UTC ( #969443=note: print w/ replies, xml ) Need Help??


in reply to Re^4: 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.

Declaring a variable with 'our' makes the the variable lexical to all enclosed blocks even across package boundaries.

See perldoc -f my and perldoc -f our for more explanation.


Comment on Re^5: Noob could use advice on simplification & optimization
Select or Download Code
Re^6: Noob could use advice on simplification & optimization
by Anonymous Monk on May 08, 2012 at 13:03 UTC

    '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
      Got it. Thanks all!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969443]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2014-04-21 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls