|
Posted by Gunnar Hjalmarsson on March 14, 2008, 1:09 am
Please log in for more thread options jh3an wrote:
> The following code doesn't make any sense, does it ?
Sure it does.
> {
> package A;
> my $a = 3;
> if( ! ($a == $A::a) ){print "not equal\n"}
> }
>
> #output will be:
> not equal
>
> Why ? I think $A::a equals $a.
> If I do not use "my" operator, output will be the one as I expect.
>
> Does "my" operator do something in this case?
It declares the lexically scoped variable $a, which is not the same
variable as the package global $A::a.
> Without my operator>>
> {
> package A;
> $a = 3;
> if(!($a == $A::a)){print "not equal\n"}
> else{ print "equal\n";}
> }
>
> #output:
> equal
In this example, $a is a package global, and $A::a is just the fully
qualified name of the very same variable.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
|