Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

What is %:: used for?

by SarahM (Monk)
on Jun 14, 2002 at 12:36 UTC ( [id://174476]=perlquestion: print w/replies, xml ) Need Help??

SarahM has asked for the wisdom of the Perl Monks concerning the following question:

I've recently stumbled across '%::'. It looks like it contains the system table for main, and you can modify it...but I'm wondering what the use of it is?

If you have a module and want to put subs or vars in main, you can use export. Within main you just use a var and its entry is added. You can use typeglobs to alias one var to another var, or to alias a ref. Is this just something that has always been there? I'd like to see any code examples, or modules that need to use this.

Replies are listed 'Best First'.
Re: What is %:: used for?
by Util (Priest) on Jun 14, 2002 at 12:59 UTC
•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

      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.
      

      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 %::.
        Yes it's in Perl! See perldoc -m Exporter, but don't stare at it too hard before you're ready to understand and respect the smoke and mirrors revealed.

        -- Randal L. Schwartz, Perl hacker

      If you're merely watching the play, don't wander around backstage, please. {grin}

      Uncalled for... Bad form, old boy.

        Which part of "{grin}" don't you understand?
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.

      I know that much...I'm looking for more of the practical use of %::.
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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://174476]
Approved by c-era
Front-paged by c-era
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-18 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found