Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Perplexed by typeglobs.

by chas (Priest)
on Feb 26, 2005 at 07:33 UTC ( #434748=note: print w/ replies, xml ) Need Help??


in reply to Perplexed by typeglobs.

For each identifier in a package, there is a symbol table entry containing slots for each of the possible types with that identifier as its "name". E.g. if we have a variable $x, a subroutine &x, an array @x, these are all held in a typeglob *x. If one sets *y = *x, then *y contains the same slots that *x does, so, for example, $y is the same as $x. One can access slots of a typglob: for example, *x{SCALAR} is a reference to $x. Using typeglobs or references to typeglobs one can pass filehandles to a subroutine. For example,

sub blah { my $filehandle = shift; print $filehandle "Blah!\n"; } blah(*STDOUT); #these both blah(\*STDOUT); #produce Blah! (and a newline)
chas
(Updated to fix typo.)


Comment on Re: Perplexed by typeglobs.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2015-07-30 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls