Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

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


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

?? The %tk and %s hashes ARE global. They are declared in the main scope.

BTW, I updated the script a bit; fixed some errors (my errors) and tweaked some things here and there.


Comment on Re^3: Noob could use advice on simplification & optimization
Re^4: Noob could use advice on simplification & optimization
by bgreg (Initiate) on May 07, 2012 at 20:33 UTC

    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.

      '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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969302]
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-09-21 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls