The reason you are getting that error is just like the error says.
you are trying to use the string 'value' as a hash reference.
$hash{key} = 'value'print "'hash{key}' is a hash reference\n" if ref(\%{$hash{key}}) eq 'H +ASH';
I'm not really sure what you are doing with this, but you could use some sort of
recursive subroutine to dig down into the hash to get what you want.
Something like this maybe.
#!/usr/local/bin/perl5.6.0 use strict; use warnings; my $hash = { h1 => { ss1 => 'Howdy' }, h2 => { hh1 => { sss1 => 'Hello' } }, s1 => 'Doody', a1 => [], }; dig( $hash ); sub dig { my ( $hole ) = @_; if( ref($hole) eq 'HASH' ) { foreach my $l ( keys %{$_[0]} ) { dig( $_[0]->{$l} ); } } elsif ( ref($hole) eq 'ARRAY' ) { print q{What do I do with an Array ref?\n}; } else { my $leaf = $hole; # leaf in a hole?!? print qq{Found a leaf in an hole! [$leaf]\n}; } }
In reply to Re: hash reference syntax?
by Wonko the sane
in thread hash reference syntax?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |