Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: my $var masked across package scope?

by InfiniteSilence (Curate)
on May 09, 2013 at 13:44 UTC ( [id://1032773]=note: print w/replies, xml ) Need Help??


in reply to my $var masked across package scope?

There's an awesome and often unused tool that comes with perldoc that will just tell you about particular Perl keywords. Using "perldoc -q my" will tell you that,

A "my" declares the listed variables to be local (lexically) to the e +nclosing block...
So, enclosing your variable declarations inside of different blocks resolves the problem. Here's a more involved example:
#!/usr/bin/env perl + + use strict; use warnings; package Foo; { my $package = __PACKAGE__; sub new { return bless {'PACKAGE'=>$package} } } package Bar; { my $package = __PACKAGE__; sub new { return bless {'PACKAGE'=>$package} } } package main; my $foo = Foo->new; my $bar = Bar->new; print $foo->{'PACKAGE'}; print qq|\n\n|; print $bar->{'PACKAGE'};

Celebrate Intellectual Diversity

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found