in reply to Blessing interior hashes
What I want to test for is like Is the underlying implementation of this blessed thing a hashref?
reftype($ref) eq 'HASH' answers that question.
reftype can be found in core module Scalar::Util.
UNIVERSAL::isa($ref, 'HASH') also answers that question.
isa is always present. It's documented in core module UNIVERSAL.
...but is it the right question? Shouldn't you be asking "Can this ref be used as a hashref?"
eval { %$ref || 1 } will answer that question.
if (eval { %$ref || 1 }) { # Hash ... } elsif (eval { @$ref || 1 }) { # Array ... } else { ... }
Update: Added isa.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Blessing interior hashes (pseudo-hashes)
by lodin (Hermit) on Oct 03, 2007 at 19:38 UTC | |
by ikegami (Patriarch) on Oct 03, 2007 at 19:42 UTC | |
|
Re^2: Blessing interior hashes
by throop (Chaplain) on Oct 03, 2007 at 17:41 UTC | |
by ikegami (Patriarch) on Oct 03, 2007 at 18:28 UTC | |
by lodin (Hermit) on Oct 03, 2007 at 19:07 UTC | |
by ikegami (Patriarch) on Oct 03, 2007 at 19:51 UTC | |
by lodin (Hermit) on Oct 03, 2007 at 20:24 UTC | |
|