http://www.perlmonks.org?node_id=334421


in reply to hash reference syntax?

Hello,

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.

print "'hash{key}' is a hash reference\n" if ref(\%{$hash{key}}) eq 'H +ASH';
$hash{key} = 'value'

and you are trying to reference it as a hash by surrounding it with '\%{ }
In Essense you are saying '\%{"value"}'

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}; } }