Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by bgreg (Initiate)
on May 07, 2012 at 20:33 UTC ( #969326=note: print w/ replies, xml ) Need Help??


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

I see. I'm missing a simple concept somewhere then, because I see they are declared with 'my'. Does this have a different behavior in your context? Also, I added several of your suggestions already and I'm working through the rest now.


Comment on Re^4: Noob could use advice on simplification & optimization
Re^5: Noob could use advice on simplification & optimization
by thundergnat (Deacon) on May 08, 2012 at 12:48 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.

    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.

      '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://969326]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-10-24 12:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (131 votes), past polls