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 | |
|
Re^2: why the variable is used this way?
by Anonymous Monk on Oct 30, 2005 at 19:47 UTC |