in reply to What does '::' mean in constructs '$::foo' and '@::foo'?

that syntax means the default main package.
Infact normally you can specify the package where a variable lives as in $package::varname and when the first part is null is read as $main::varname

update: probably there are other package definitions when you encounter such syntaxes: inside the scope of a package pack_name if you write $varname it reads $pack_name::varname while $::varname reads $main::varname

L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: What does '::' mean in constructs '$::foo' and '@::foo'?
by ikegami (Patriarch) on Oct 06, 2015 at 15:33 UTC
    Nit: It actually refers the var in the root namespace, but main is aliased to the root namespace, so the following all refer to the same var:
    $::var $main::var $main::main::var $main::main::main::var etc
Re^2: What does '::' mean in constructs '$::foo' and '@::foo'?
by jmeek (Initiate) on Oct 06, 2015 at 15:32 UTC
    So @::foo is just shorthand for @main::foo, and the need for this syntax has been mostly rendered obsolete since it became possible to use our @foo; instead of use vars ( @foo );. (Right?) Many thanks.

      No. Assuming the purpose is to "defeat" use strict;, it was made obsolete by use vars qw( @foo );.

      perl -e' use strict; @foo = 123; print "ok\n"; ' Global symbol "@foo" requires explicit package name at -e line 3. Execution of -e aborted due to compilation errors. $ perl -e' use strict; use vars qw( @foo ); @foo = 123; print "ok\n"; ' ok

      But since strict was introduced in Perl 5.000 and vars was introduced in Perl 5.002, it's safe to say that was not the book's reason for using @::foo.

      In fact, it's not obsolete. You still need to use fully qualified names to refer to variables in namespaces other than the current one.

      use Data::Dumper qw( Dumper ); local $Data::Dumper::Useqq = 1; local $Data::Dumper::Sortkeys = 1; print(Dumper($data));