in reply to accessing a hash via reference
# what is going on here? What am i dealing with? print " $token->[2]\n "; # how do i dereference this?
use Data::Dumper; print Dumper $token->[2]; # or w/o Data::Dumper print join(":", keys %{$token->[2]}), "\n";
my %hash = $token->[2]; # below wont work unless i feed it a hash # my $key; # foreach $key (keys %hash) { # print "at $key we have $hash{$key}\n"; # }
Or, alternatively (but the above is better, because this way below makes a copy of the data in the hash):my $hash = $token->[2]; foreach my $key (keys %$hash) { printf "at %s we have %s\n", $key, $hash->{$key}; }
my %hash = %{$token->[2]}; foreach my $key (keys %hash) { printf "at %s we have %s\n", $key, $hash{$key}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: accessing a hash via reference
by richill (Monk) on Sep 03, 2006 at 13:30 UTC | |
by Fletch (Bishop) on Sep 03, 2006 at 13:56 UTC | |
by richill (Monk) on Sep 03, 2006 at 14:09 UTC |