The following is what I was trying to test out with my first program:
use strict; use warnings; use 5.010; my %h = qw{a 1 b 2}; my @h = (100, 200, 300); my $h = 10; *all = \%h; *all = \@h; *all = \$h; #<overwriting that strange variable??> say ${*all}{a}; say ${*all}[0]; say ${*all}; --output:-- 1 100 10
It demonstrates that a type glob has "slots" for each perl type that can be assigned to the same variable name, in this case a hash, an array, and a scalar. There are also slots for subroutines, etc. Then when you dereference the glob, which has many references stored in it, the glob dereferences the correct reference based on the context. In the example, the first dereference involves a hash subscript, {a}, so the glob chooses the hash reference and dereferences that. The second dereference involves an array subscript, [0], so the glob dereferences the array reference, etc. Glob is smart.
No news to you, obviously. :)
In reply to Re^2: type glob
by 7stud
in thread type glob
by 7stud
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |