Typeglobs vs References

K

Krishna Chaitanya

Hi, i've been reading Programming in Perl and perldata, perlref, etc
for understanding typeglobs and how they relate to references.
Frankly, i found the material a bit daunting for someone who's just
started in perl. In many places, I found statements to the effect that
typeglobs and references can be used interchangeably. How is this
possible? Can any1 pls point me to easier articles/tutorials which
give a step-by-step explanation? any examples that you can rig up to
clarify this?

Thanks a lot...
 
S

sln

Hi, i've been reading Programming in Perl and perldata, perlref, etc
for understanding typeglobs and how they relate to references.
Frankly, i found the material a bit daunting for someone who's just
started in perl. In many places, I found statements to the effect that
typeglobs and references can be used interchangeably. How is this
possible? Can any1 pls point me to easier articles/tutorials which
give a step-by-step explanation? any examples that you can rig up to
clarify this?

Thanks a lot...

Why don't you stay away from typeglobs. Then you understand references
completely and are now moving on to typeglobs as a beginniner, or have you
learned typeglobs first?

-sln
 
K

Krishna Chaitanya

Learned references and their uses in creating data structures. Now
moving onto typeglobs...
 
R

RedGrittyBrick

Krishna said:

I suggest you ignore typeglobs. I've managed for decades without knowing
about them. If you are learning Perl I think your efforts would be more
usefully directed to other aspects of Perl. I'd learn popular varieties
of Perl OO before typeglobs.

Just my ¤0.02 worth.
 
K

Krishna Chaitanya

I was forced to notice them while using modules like IPC::* (open3,
etc). I agree most perl coding can do without typeglobs, but I
definitely wouldn't want to be ignorant on a day when I have to use
them. Started reading up about these entities.....they are definitely
mysterious (esp, in "perlsub" - passing arguments by reference vs.
indirection).

Also, dealing with filehandles, passing them around to subroutines,
don't you agree we need to know abt typeglobs?

Thanks...
 
P

Peter Makholm

Krishna Chaitanya said:
Also, dealing with filehandles, passing them around to subroutines,
don't you agree we need to know abt typeglobs?

Except for the third argument to open3 I can't remember I have any
problmes with using lexical filehandles alle places where I'm using
filehandles.

Only time I messes around with typeglobs are when I need aliases to
names where references wouldn't do. Most of the times this is for
autogenerated functions in a package. But even for this I should
probably use Sub::Install instead to hide the messing around with
typeglobs.

//Makholm
 
R

RedGrittyBrick

Krishna said:
Also, dealing with filehandles, passing them around to subroutines,
don't you agree we need to know abt typeglobs?

I don't agree.

-----------------------------8<------------------------------
#!/usr/bin/perl
use strict;
use warnings;

open my $fh, '>', "foo.txt" or die "can't open foo.txt - $!\n";
foo($fh);
close $fh;

sub foo {
my $handle = shift;
print $handle "foo!\n" or die "can't write - $!\n";
}
-----------------------------8<------------------------------
perl t2.pl
cat foo.txt
foo!
 
K

Krishna Chaitanya

Yeah I agree with your point on lexical file-handles. Read last night
that it is a newer feature. Older code does use type-globs and bare-
word identifiers.

But as a matter of curiosity, is it everyone's opinion here that
trying to understand type-globs is totally unproductive and not worth
one's time?

There has to be some to the concept, after all?
 
U

Uri Guttman

KC> But as a matter of curiosity, is it everyone's opinion here that
KC> trying to understand type-globs is totally unproductive and not worth
KC> one's time?

it isn't worth the time until you need to do something with the symbol
table. and that is rarely needed so why study typeglobs now?

KC> There has to be some to the concept, after all?

sure, they are a way to access entries in the symbol table. you can also
do that with symrefs (evil) and accessing the stash. study it if you
want but you just don't need typeglobs in normal perl coding.

uri
 
C

Charlton Wilbur

KC> But as a matter of curiosity, is it everyone's opinion here that
KC> trying to understand type-globs is totally unproductive and not
KC> worth one's time?

It is my opinion that trying to understand typeglobs is something you
should do only when you need to use typeglobs for something.

This has been my attitude with formats, for instance, and the last time
I looked at them was in 1996. I have no idea how they work, and it
hasn't hampered me in the slightest.

Charlton
 
P

Peter Scott

KC> But as a matter of curiosity, is it everyone's opinion here that
KC> trying to understand type-globs is totally unproductive and not
KC> worth one's time?

It is my opinion that trying to understand typeglobs is something you
should do only when you need to use typeglobs for something.

This has been my attitude with formats, for instance, and the last time
I looked at them was in 1996. I have no idea how they work, and it
hasn't hampered me in the slightest.

Well said. Sometimes I think that most of the use of typeglobs in the
last decade has been for MJD to produce mind-bending "Tricks of the
Wizards" talks...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top