In general, if you've got a reference to a hash - let's call it $ref - then you can work with it like this:
More info can be found here: perlref or here: References quick reference (or, newly, here if you speak German: (lang: de) Referenzen) or by typing 'perldoc perlref' at your command line.#construct a ref to an anonymous hash: my $ref = {andy => 'likes cake'}; #note *curly* brackets #another way my %hash = (andy => 'likes beer too'); $ref = \%hash; #normal brackets + of course #get at one specific value print $ref->{andy}; #another way print $$ref{andy}; #get all the keys print keys %$ref; #get all the values print values %$ref; #get key/value pairs while (my ($key, $val) = each %$ref) {print "$key = $val"} #copy the hash into a new hash my %newhash = %$ref #if you use the -> syntax with references to references, then you can +omit the ->s, after the first one, like this: my $ref = { andy => {eats => 'cake'}}; print $ref->{andy}{eats}; #note only one -> necessary
hth,
andy.
update: and the book "Effective Perl Programming" has an excellent explanation, very full, with pictures.
In reply to dereferencing syntax Re: Getting keys/values from a referenced hash
by andye
in thread Getting keys/values from a referenced hash
by professa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |