ddtl said:
But why not use $@$fh or $%$fh - it shouldn't be ambiguous -
the first $ indicates that fh is a scalar.
That's first counting from the right or from the leaves of the
parse tree. While in execution order the leafmost part of the
parse tree is usually first most humans when reading a L2R rendered
language will read "first" as meaning leftmost.
The second funny character
indicates that we dereference scalar and getting to the typeglob
If you wanted to unambiguously get to a typeglob it would be a *.
However there's a grey area between GLOBs and SCALARs - this is for
historical reasons. Just like references can be handled as scalars so
can GLOBs. So for this reason you can use $ even though I'd always
use * for the sake of clarity. You cannot use a @ or a % because $foo
is not usable as a hashref or an arrayref.
my $foo = \*bar; # $foo contains a GLOBref
# Try to dereference $foo as a GLOB
print *$foo; # prints *main::bar
print ref \*$foo; # prints GLOB
# Try to dereference $foo as a scalar but actually get a GLOB
print ref \$$foo; # prints GLOB
# Try to dereference $foo as an array
print ref \@$foo; # error - Not an ARRAY reference
(typeglob is either a scalar, or array or hash, so every funny
character should do - why give special privilege to $?).
No. A reference is a special type of scalar value that points to a
single thingy. A (fake) glob is a special type of scalar value that
points to one thingy of each type.
If $foo was a reference to a reference to a hash you'd use %{${$foo}}
or just %$$foo.
If $foo was a reference to a glob to and you want the hash part of the
glob I'd use %{*{$foo}} but because GLOBs can sometimes be treated as
SCALAR you can still just use %$$foo.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\