Re: What is %:: used for?
by Util (Priest) on Jun 14, 2002 at 12:59 UTC
|
%:: is a short name for %::main. The general name of the symbol table of any package is %::package
See the "Symbol Tables" section of perlmod for some usages.
See Dominus's "Tricks of the Wizards" class for more interesting uses, like how to do lightweight exporting without using the Export module.
And yes, Exporter is written in Perl, in two pieces:
Exporter.pm
Exporter/Heavy.pm
Update: added text below
Finally, here are some enlightening discussions on some advanced uses:
| [reply] [d/l] [select] |
•Re: What is %:: used for?
by merlyn (Sage) on Jun 14, 2002 at 12:46 UTC
|
If you have a module and want to put subs or vars in main, you can use export.
How do you think export does it? By direct
symbol table access, accessing things like %::
and %CGI:: and so on!
If you're merely watching the play, don't wander around
backstage, please. {grin}
-- Randal L. Schwartz, Perl hacker
| [reply] |
|
How do you think export does it? By direct symbol table access, accessing things like %:: and %CGI:: and so on!
While Exporter does access the symbol table directly by using typeglobs, it doesn't use any hash ending in ::. This is probably because it exports symbols, not symbol tables.
I searched both Exporter.pm and Exporter::Heavy.pm. The only reference to something ending in :: was:
Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT")
if $_[0] =~ /^Unable to create sub named "(.*?)::"/;
in Exporter/Heavy.pm.
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
| [reply] [d/l] |
|
Is export written in perl? I would have thought that export was written in the c code that makes up perl! But if export is written in perl, I can definitely see the use of %::.
| [reply] |
|
| [reply] |
|
|
| [reply] |
|
Which part of "{grin}" don't you understand?
| [reply] |
|
|
|
Re: What is %:: used for?
by derby (Abbot) on Jun 14, 2002 at 12:50 UTC
|
checkout perlmod under the heading "Symbol Tables." To qoute,
The symbol table for a package happens to be stored in the hash of that name with two colons appended. The main symbol table's name is thus %main::, or %:: for short.
-derby
update: removed the third line from the qoute. | [reply] |
|
I know that much...I'm looking for more of the practical use of %::.
| [reply] |
Re: What is %:: used for?
by samtregar (Abbot) on Jun 15, 2002 at 03:14 UTC
|
You might take a look at a module of mine, Devel::Profiler. I use %main:: as a jumping-off point to scan all the symbol tables in the system looking for subroutines to profile. I won't claim the code is simple but at least it's better commented than Exporter.pm!
-sam
| [reply] [d/l] |