Hi, thanks for the response.
I am trying to use a type glob to access values in a hash.
Why?
I read about them in the docs, and I wanted to try them out.
You're trying to reach a variable via a type glob in the symbol table, yet the variable in question isn't in the symbol table. It's a lexical (my) variable.
Hmm...things aren't as straight forward as I was led to believe. Ok, I did some reading about symbol tables, and if I understand them correctly, they are just hashes that contain the variables in your program. The keys in the hash are the variable's names and the values are the variable's values. However, the docs say that the symbol table hash does not contain "my" variables--only dynamic variables. What is a dynamic variable? Anything that isn't a my variable?
Well, if we are always told to use 'my' to declare variables, how does a program create "dynamic variables"?
I discovered this "solution" to my original question:
#use strict; #use warnings; use 5.010; %h = qw{a 1 b 2}; @h = (100, 200, 300); $h = 10; say $h{a}; say $h[0]; say $h; my $href = *h{HASH}; my %hash = %{$href}; say $hash{a}; --output:-- 1 100 10 1
I have a question about this code:
my %h1 = qw{a 1 b 2}; *h2 = \%h1;
How is that different from doing this:
my $href = \%h1;
Is h2 one of those dynamic variables?
say *h2; --output:-- main::h2
Hey, it's in the hash table. Oh boy, I'm on a roll:
say $main::h2{a}; --output:-- 1
In reply to Re^2: type glob
by 7stud
in thread type glob
by 7stud
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |