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.
In reply to hash reference syntax? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |