in reply to why the variable is used this way?

Perl needs to know that you want to interpolate $pkg and not $pkg::_ATTR, which would be the variable $_ATTR in the package pkg. Another way to tell Perl to ignore the colons is the following:

@{"$pkg\::_ATTR"} = @_

which is not necessarily less obfuscated though.

As a small example of the differences, look at the following:

package pkg; $_ATTR = 'I am $_ATTR from ' . __PACKAGE__; package main; $pkg = 'I am $pkg from ' . __PACKAGE__; print "1. $pkg::_ATTR\n"; print "2. $pkg\::_ATTR\n"; print "3. ${pkg}::_ATTR\n";

Replies are listed 'Best First'.
Re^2: why the variable is used this way?
by sauoq (Abbot) on Oct 30, 2005 at 19:49 UTC
    which is not necessarily less obfuscated though.

    Yet another way which is, perhaps, a little more clear:

    @{$pkg . '::_ATTR'} = @_;
    It's probably expected, though, that anyone reading or changing code using caller and symbolic refs will understand the other forms.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re^2: why the variable is used this way?
by Anonymous Monk on Oct 30, 2005 at 19:47 UTC
    Thanks, Corion. that helped me a lot. serah