C:\>perl -MO=Deparse -e "$foo = 'bar'"; $foo = 'bar'; -e syntax OK C:\>perl -MO=Deparse -e "$main::foo = 'bar'"; $foo = 'bar'; -e syntax OK C:\>perl -MO=Deparse -e "$::foo = 'bar'"; $foo = 'bar'; -e syntax OK
Superficially these all parse the same. But as Corion notes the :: is significant as it signifies a package rather than a lexical variable. As soon as your current package is not main but some other package, or as soon as $foo is a lexical variable (and $::foo will never be) they are different.
C:\>perl -MO=Deparse -e "package Foo; my $foo = 'bar'"; package Foo; my $foo = 'bar'; -e syntax OK C:\>perl -MO=Deparse -e "package Foo; my $::foo = 'bar'"; "my" variable $::foo can't be in a package at -e line 1, near "my $::f +oo " Can't use global $::foo in "my" at -e line 1, near "my $::foo " -e had compilation errors. C:\>perl -e "package Foo; $::foo = 'foo'; print $foo" C:\>perl -e "package Foo; $::foo = 'foo'; print $main::foo" foo C:\>
cheers
tachyon
In reply to Re: syntax/operator question
by tachyon
in thread syntax/operator question
by rtremaine
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |