One slight problem, in v5.8.8 (ActiveState build 820), this reports that the array reference is a hash reference:
use strict; use warnings; my $aref = [qw(1 2 3 4)]; if ( eval { %$aref; 1 } ) { print "aref is a href\n"; my %hash = %$aref; }
But it dies with Can't coerce array into hash when you try to dereference it outside of the eval. In 5.6.1, it does not report that the array ref is a hash ref. This seems to fix it:
if ( eval { my $foo = %$aref; 1 } ) { print "aref is a href\n"; my %hash = %$aref; }
In other code similar to the first instance ( but not that particular code for some reason), I did get the warning:
Pseudo-hashes are deprecated
which explains why an array reference could be considered a hash reference.

Update: What I've ended up using is this:

sub isa_hash { no warnings 'void'; my $hsh = shift(); return if eval { @$hsh; 1 }; return 1 if eval { %$hsh; 1 }; return; } sub isa_array { no warnings 'void'; my $arr = shift(); return 1 if eval { @$arr; 1 }; return; }
UNIVERSAL::isa() is looking simpler all the time (even if wrong in obscure instances).

Another Update: Borrowed from diotalevi's use perl journal:

if ( eval { 1 + %$possible_href } ) { return 1; }

In reply to Re^5: RFC: DBIx::Iterator by runrig
in thread RFC: DBIx::Iterator by runrig

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.