Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I ultimately want to traverse a hash of unknown topology to determine if I have reached leaf nodes (no hashes exist beneath the current reference). The following test code:
gives me the error Can't use string ("value") as a HASH ref while "strict refs" in use when I try to test $hash{key} for a type that it isn't on the final line.#!/usr/bin/perl use strict; my %hash; print "'hash' is a hash reference\n" if ref(\%hash) eq 'HASH'; $hash{key} = 'value'; print "'hash' is still a hash reference\n" if ref(\%hash) eq 'HASH'; print "'hash{key}' is a scalar reference\n" if ref(\$hash{key}) eq 'SC +ALAR'; print "'hash{key}' is a hash reference\n" if ref(\%{$hash{key}}) eq 'H +ASH';
How do I go about testing each node in the tree to determine whether I can go further down the structure?
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash reference syntax?
by tachyon (Chancellor) on Mar 06, 2004 at 00:06 UTC | |
by Anonymous Monk on Mar 06, 2004 at 00:53 UTC | |
by davido (Cardinal) on Mar 06, 2004 at 05:20 UTC | |
|
Re: hash reference syntax?
by Wonko the sane (Curate) on Mar 06, 2004 at 00:15 UTC | |
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 |