<br><br><div><span class="gmail_quote">On 8/1/05, <b class="gmail_sendername">Yitzchak Scott-Thoennes</b> &lt;<a href="mailto:sthoenna@efn.org">sthoenna@efn.org</a>&gt; 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.&nbsp;&nbsp;See perldoc -f ref<br><br>while ( my ($key, $val) = each %outer_hash ) {<br>&nbsp;&nbsp; if ( ref $val eq &quot;HASH&quot; ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br>&nbsp;&nbsp; } elsif ( ref $val eq &quot;ARRAY&quot; ) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br>&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;warn &quot;I don't think we're in Kansas anymore, Toto&quot;;<br>&nbsp;&nbsp; }<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.&nbsp; Objects are still references,
they just have &quot;specialness&quot; (blessed).&nbsp; 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>