<br><br><div><span class="gmail_quote">On 8/1/05, <b class="gmail_sendername">Yitzchak Scott-Thoennes</b> <<a href="mailto:sthoenna@efn.org">sthoenna@efn.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
If there are no objects involved, this is easy. See perldoc -f ref<br><br>while ( my ($key, $val) = each %outer_hash ) {<br> if ( ref $val eq "HASH" ) {<br> ...<br> } elsif ( ref $val eq "ARRAY" ) {
<br> ...<br> } else {<br> warn "I don't think we're in Kansas anymore, Toto";<br> }<br>}<br><br>If there are objects involved, the problem is not generally solvable; you<br>have to decide what you will treat as a hash and what as an array.
<br></blockquote></div><br>
You can still make this work (although not quite as nicely in some
cases) if your values are objects. Objects are still references,
they just have "specialness" (blessed). By changing the above
equality tests to regexes, you can treat objects as the base data type:<br>
<br>
my $ref = ref $val;<br>
if (!defined $ref) {<br>
# simple scalar value<br>
}<br>
elsif ($ref =~ /HASH/) {<br>
...<br>
}<br>
elsif ($ref =~ /ARRAY/) {<br>
...<br>
}<br>
# other conditions for different data types (SCALAR, CODE, etc.)<br>
else {<br>
# catch-all if you didn't specifically handle the type<br>
}<br>
<br>
-- Ivan<br>