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:use strict; use warnings; my $aref = [qw(1 2 3 4)]; if ( eval { %$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:if ( eval { my $foo = %$aref; 1 } ) { print "aref is a href\n"; my %hash = %$aref; }
which explains why an array reference could be considered a hash reference.Pseudo-hashes are deprecated
Update: What I've ended up using is this:
UNIVERSAL::isa() is looking simpler all the time (even if wrong in obscure instances).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; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |