Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Consider, for example, a normal hash reference, a blessed hash, a tied hash reference, and a blessed scalar with hash dereferencing overloading.
[....] You could use UNIVERSAL:­:isa() to check if the entity seems to be a built-in hash (but that fails for the last two items and it's really bad style).

I believe and my testing confirms that UNIVERSAL::isa() actually works in all but the last case, not just 2 of 4 as you claim.

I find it ironic, if this is meant to be used for what you claim, that it has repeated the mistake of expecting people to use methods on hash references when methods can't be used on normal hash references (Perl dies due to "unblessed reference"), not even on a reference to an (unblessed) tied hash (so 2 of your 4 cases, including the by-far most common one).

So it appears we have yet another inconvenient and/or incomplete way to check whether something can be used as a hash. I'll certainly be sticking with UNIVERSAL::isa() for much of my simpler code since it is many times simpler than any of the (possibly) more accurate alternatives, it covers the vast majority of cases, and objects for which it fails can easily be fixed such that it works for them as well; plus it works on non-bleeding-edge versions of Perl.

- tye        


In reply to Re^2: I don't understand UNIVERSAL::DOES() (hash method?!) by tye
in thread I don't understand UNIVERSAL::DOES() by rlb3

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-19 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found