It looks like you are using Req_Trace as a setter/getter, and that Req_Trace should only be set to a hash ref if set at all. In the above code, it looks like you are checking to see if its a hash ref after it's already been set, which IMO is the wrong place to be doing that. You should check to see if its a hash ref while it is being set, and in the above code, you would/may only need to check to see if it is set at all.

That being said, to check to see if Req_Trace is passed a hash reference, some here would say to use UNIVERSAL::isa($rt_arg, 'HASH'), and some would say ref($rt_arg) eq 'HASH' is fine. Either way is 'broken' in one way or another:
my $aref = [ 1..5 ]; bless $aref, 'HASH'; # An array ref now thinks it's a hash ref print "aref is a HASH\n" if ref($aref) eq 'HASH'; print "aref is a HASH\n" if UNIVERSAL::isa($aref, 'HASH'); my $href = { 0..9 }; # This is ok print "href is a hash\n" if ref($href) eq 'HASH'; bless $href, 'Some::Package'; # This may not be ok print "href is not a hash\n" unless ref($href) eq 'HASH';
IMO, if you don't want to accept a blessed object which happens to be implemented as a hash ref (which is fine IMO), then ref is fine (I just want a hash ref, I don't want no damn stinkin' objects! :-) (update: oops, but it also accepts an object that thinks its a hash :). If you want to make absolutely sure that the argument passed is a hash reference, blessed or not, then you use Scalar::Util::reftype(). If you think people deserve what they get if they bless a non-hash reference into a 'HASH' package (I would lean this way also), then UNIVERSAL::isa is fine too.

In reply to Re: Re: Is "ref $date eq 'ARRAY'" wrong? by runrig
in thread Is "ref $date eq 'ARRAY'" wrong? by bronto

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.