Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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.

Replies are listed 'Best First'.
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?
[robby_dobby]: This anonymonk's post reads weird to me
[robby_dobby]: Other than the content, that Chrome would not allow submitting code sounds like something funky going on there :P
[erix]: lazyness-driven inventio :)
[erix]: "the dog ate my homework"
[Eily]: looks more like "all my plates are broken and I don't understand why. Also I can't retrieve the broken parts because the elephant in the room is on the way"
[ambrus]: Eily: also webpages aren't displayed on my monitor no matter what I click with the mouse, and there's a blackout right now, could that be a problem?

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2017-04-25 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (453 votes). Check out past polls.