I'm looking at the camel book again and feeling confused. This seems to
happen whenever I look at the camel book. The camel book (3rd edition) page
78 says:

 

"Perl uses an special type called a typeglob to hold an entire symbol table
entry."

 

Ahhhh. OK, if  Larry says so. I don't understand why I would ever want a
typeglob.

 

It continues.

One of the uses of typelgobs, (or references thereto) is for passing or
storing filehandles. If you want to store a file handle, do it this way: 

 

$fh = *STDOUT;

 

I'm lost!

 

What does the "*" mean? I guess the "*" syntax is intended to suggest wild
card hinting that $fh contains { SCALAR=>$STDOUT, HASH=>%STDOUT,
ARRAY=>@STDOUT}? Correct?  

 

Continuing with the camel book on the top of page 79:

 

Sub newopen {

     my $path = shift;

     local *FH;

.

Why "local" and not "my" here?

Just what exactly is FH now? Is it an array that contains six empty values,
one for each: $FH, @FH, %FH and &FH?

. continuing

 

   open(FH, $path) or return undef;

 

So FH is a file handle. Are file handles the only type of value is that is
not preceded by a "&" or "$" or "%" or "@"? But FH was declared with a "*".
What is the rule for knowing when to use a "*" and when not to use a "*"?

 

}

$fh = newopen('/etc/password');

 

. 

So now I skip to page 296 and  try the following experiment:

perl -e ' package pkg; $x = "abc"; @x=(1,3,3); %x=(a=>b,c=>d); print
${*pkg::x{SCALAR}}."\n".join(",", keys %{*pkg::x{HASH}})."\n".
join(",",@{*pkg::x{ARRAY}})."\n" ;'

 

It works! Ah hah! Now I understand typeglobs.

 

perl -e ' local *x; $x = "abc"; @x=(1,3,3); %x=(a=>b,c=>d); print
${*x{SCALAR}}."\n".join(",", keys %{*x{HASH}})."\n".
join(",",@{*x{ARRAY}})."\n" ;'

 

This works too! 

 

Now Larry (or Tom, or John) says

This syntax is primarily used to get at the internal file handle or
directory handle reference, because the other internal references are
already accessible in other ways.

 

Ah hah! Here is the root of my confusion: Why, when inventing the perl
language, did Larry define a special punctuation character for each type
(scalar, array, hash) except IO? 

 

That is soooo confusing! So the real reason to use typeglobs is because
there is no special punctuation character for *x{IO}. That is so
inconsistent! Why is there no special prefix character for file handles like
there is for hashes, arrays and scalars?

 

Thanks,

  Siegfried

Reply via email to