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

Re: Perplexed by typeglobs.

by sauoq (Abbot)
on Feb 26, 2005 at 10:49 UTC ( [id://434761]=note: print w/replies, xml ) Need Help??


in reply to Perplexed by typeglobs.

Right now, I feel my typeglob related ignorance is hampering my study of perl.

Don't worry... it probably isn't. ;-)

It is rarely necessary to use typeglobs directly. Especially these days (so long as you use a current version of perl) since support for using lexicals for filehandles has been built into open(). Passing filehandles was once their most common use.

Another use for them that doesn't get as much attention nowadays as I think it should is to create constants. Try the following code for example...

*foo = \"foo"; print "foo is $foo.\n"; $foo = "bar"; # Run time error. Modification of read-only value att +empted.
I prefer this to use constant FOO => "foo"; since those constants don't interpolate in strings (without jumping through the right hoops.)

I'm not suggesting that you shouldn't learn about them, of course. Only that you probably don't need them. They are indispensable for some introspective tasks and if you are writing a debugger or data dumper or something, you might need them afterall. But, most tasks can (and should) be done without them.

-sauoq
"My two cents aren't worth a dime.";

Log In?
Username:
Password:

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

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

    No recent polls found