Try the ref() function.
if (ref($hash{$data}) eq 'HASH') {}
Hth. Sid.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf
Of Pete Emerson
Sent: Thursday, December 06, 2001 9:03 AM
To: [EMAIL PROTECTED]
Subject: detecting a hash of hashes
Here is an example of what I'm doing to detect whether I've got a scalar
value in my hash or a hash of hashes:
#!/usr/bin/perl -w
use strict;
my %hash;
$hash{name}='Pete';
$hash{color}{favorite}='Blue';
$hash{color}{car}='Silver';
$hash{color}{house}='White';
foreach my $data (keys %hash) {
if ($hash{$data}!~/HASH\(\S+\)/) {
print "\$hash{$data} --> $hash{$data}\n";
} else {
foreach my $second (keys %{$hash{$data}}) {
print "\$hash{$data}{$second} --> $second\n";
}
}
}
Is there a better way to do this that doesn't use a regex to detect the
existence of a hash vs. a scalar value?
Pete
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]