Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Is this a bug in Perl scope?

by trwww (Priest)
on Jul 23, 2012 at 21:29 UTC ( #983238=note: print w/replies, xml ) Need Help??


in reply to Is this a bug in Perl scope?

This behavior is documented very clearly:

perldoc -f my A "my" declares the listed variables to be local (lexically) to the enclosing block, file, or "eval".

There no such thing as a "package scope". To do what you want you'd have to use blocks:

$ perl use strict; use warnings; { package one; my $var = 1; } { package two; my $var = 5; } package main; print "$var\n"; Global symbol "$var" requires explicit package name at - line 16. Execution of - aborted due to compilation errors.

Also, FYI warnings and strict are filescoped also if they aren't in a more specific container.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983238]
help
Chatterbox?
and the fire pops...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2017-01-24 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (208 votes). Check out past polls.