in reply to Re: type glob
in thread type glob
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: type glob
by ikegami (Patriarch) on Nov 17, 2009 at 19:20 UTC | |
|
Re^3: type glob
by JadeNB (Chaplain) on Nov 17, 2009 at 19:46 UTC | |
by 7stud (Deacon) on Nov 17, 2009 at 20:22 UTC | |
by ikegami (Patriarch) on Nov 17, 2009 at 22:19 UTC | |
by JadeNB (Chaplain) on Nov 18, 2009 at 15:53 UTC | |
by ikegami (Patriarch) on Nov 18, 2009 at 19:03 UTC | |
| |
by przemo (Scribe) on Nov 17, 2009 at 20:52 UTC | |
by JadeNB (Chaplain) on Nov 17, 2009 at 20:33 UTC | |
by Anonymous Monk on Nov 18, 2009 at 03:13 UTC | |
by JadeNB (Chaplain) on Nov 18, 2009 at 15:57 UTC | |
by 7stud (Deacon) on Nov 18, 2009 at 10:11 UTC |