The result, which puzzled me at first, will be:use strict; use warnings; package Szyewicki; our ($Robert); $Robert = "the boss"; package PoolHall; our ($Robert); $Robert = "the darts expert"; package Szyewicki; print "Here at work, 'Robert' is $Robert, but over at the pool hall, ' +Robert' is $PoolHall::Robert\n";
It took me quite a while to decypher why: the lexical scope of the 2nd our, under package PoolHall, is the file, so, when we switch to package Szyewicki, it's still in effect, making $Robert a lexical alias to package variable $Szyewicki::Robert. To work as expected and intended, the code must be:Here at work, 'Robert' is the darts expert, but over at the pool hall, + 'Robert' is the darts expert
The 3rd our alias $Robert to $Szyewicki::Robert.use strict; use warnings; package Szyewicki; our ($Robert); $Robert = "the boss"; package PoolHall; our ($Robert); $Robert = "the darts expert"; package Szyewicki; our ($Robert); print "Here at work, 'Robert' is $Robert, but over at the pool hall, ' +Robert' is $PoolHall::Robert\n";
In reply to Re: Variable Scoping in Perl: the basics
by marcelpaulo
in thread Variable Scoping in Perl: the basics
by arturo
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |