Qualified Names
You can refer to identifiers[137] in other packages by prefixing (“qualifying”) the identifier with the
package name and a double colon: $Package::Variable. If the package name is
null, the main package is assumed.
That is, $::sail is equivalent to
$main::sail.[138]
The old package delimiter was a single quote, so in very old
Perl programs you’ll see variables like $main'sail and $somepack'horse. But the double colon is now
the preferred delimiter, in part because it’s more readable to humans,
and in part because it’s more readable to emacs macros. It also makes C++ programmers
feel like they know what was going on—as opposed to using the single
quote as the separator, which was there to make Ada programmers feel
like they knew what’s going on. Because the old-fashioned syntax is
still supported for backward compatibility, if you try to use a string
like "This is $owner's house",
you’ll be accessing $owner::s; that
is, the $s variable in package
owner, which is probably not what
you meant. Use braces to disambiguate, as in "This is ${owner}'s house".
The double colon can be used to chain together identifiers in a
package name: $Red::Blue::var. This
means the $var belonging to the
Red::Blue package. The Red::Blue package has nothing to do with any
Red or Blue packages that might happen to exist.
That is, a relationship between Red::Blue and Red or Blue may have meaning to the person writing or using the program, but it means nothing to Perl. (Well, other than the fact ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access