in reply to hash reference syntax?
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}; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: hash reference syntax?
by Anonymous Monk on Mar 06, 2004 at 00:50 UTC | |
by tachyon (Chancellor) on Mar 06, 2004 at 01:46 UTC | |
by Anonymous Monk on Mar 06, 2004 at 06:45 UTC |