in reply to type glob
Can't use an undefined value as a HASH reference
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.
How can I use a type glob to get at the hash's values?
Implicitly, if the glob is in the symbol table:
my %h1 = qw{a 1 b 2}; *h2 = \%h1; # Create and initialise glob print %h2, "\n"; # Access hash referenced by glob
Explicitly, if the glob is in the symbol table:
my %h1 = qw{a 1 b 2}; *h2 = \%h1; # Create and initialise glob print %{*h2}, "\n"; # Access hash referenced by glob
Indirectly, if the glob is in the symbol table:
my %h1 = qw{a 1 b 2}; my $glob = *h2; # Create glob *$glob = \%h1; # Initialise glob print %$glob, "\n"; # Access hash referenced by glob
Indirectly, if the glob is outside the symbol table:
sub new_glob { return local *X } my %h = qw{a 1 b 2}; my $glob = new_glob(); # Create glob *$glob = \%h; # Initialise glob print %$glob, "\n"; # Access hash referenced by glob
I am trying to use a type glob to access values in a hash.
Why?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: type glob
by 7stud (Deacon) on Nov 17, 2009 at 14:11 UTC | |
by ikegami (Patriarch) on Nov 17, 2009 at 19:20 UTC | |
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 JadeNB (Chaplain) on Nov 17, 2009 at 20:33 UTC | |
by Anonymous Monk on Nov 18, 2009 at 03:13 UTC | |
| |
by przemo (Scribe) on Nov 17, 2009 at 20:52 UTC | |
|
Re^2: type glob
by 7stud (Deacon) on Nov 17, 2009 at 15:04 UTC | |
by Khen1950fx (Canon) on Nov 17, 2009 at 20:03 UTC |