Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Defining a subroutine in another package

by Aristotle (Chancellor)
on Jan 27, 2002 at 03:33 UTC ( [id://141854]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Defining a subroutine in another package
in thread Defining a subroutine in another package

Ah so I can use them that way. Data::Dumper produces entries like 'UNIVERSAL::' => *{'::UNIVERSAL::'} for keys denoting a package name, which confused me - can you explain what that is? Is that a symbolic typeglob reference, or something completely different? (Incidentally, typeglobs are the only part of Perl I never even came close to grokking. I understand what they are supposed to be, but the concept is still very alien.)

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Re: Re: Defining a subroutine in another package
by chromatic (Archbishop) on Jan 28, 2002 at 06:04 UTC
    I think it's just there to look pretty. The leading package separator means it's in package main. The trailing package separator gets at the package stash. The typeglob dereference does point it at the typeglob. I'm not sure I'd call it symbolic, as a typeglob is sort of a special kind of hash...

    All typeglobs do is associate the seven things that can be named with global names. Think of them as hashes that can only hold six keys -- SCALAR, ARRAY, HASH, CODE, IO, FORMAT. These are called slots, and you can get at the content of a glob by using the slot name as you would a hash key. The global (non-lexical) $foo, @foo, %foo, *foo, and &foo can all live within the typeglob *foo. Internally, anything that tries to use something with the name 'foo' will be resolved to use one of those things. Perl grabs the appropriate glob (resolving package names as necessary), then grabs the requested item from the appropriate glob slot.

    Again, these are all things that have global and not lexical names.

    You can copy typeglobs and assign to them. If you assign it a reference to something, it'll automatically populate (or overwrite) the appropriate slot. That's how Exporter works:

    *{$package . '::mynewsub'} = \&mynewsub;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://141854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found