Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Re: Re: Re: has it been blessed?

by dragonchild (Archbishop)
on Mar 07, 2002 at 20:44 UTC ( #150122=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: has it been blessed?
in thread has it been blessed?

if (UNIVERSAL::isa($obj, 'UNIVERSAL')) { is more than enough. If it's not a reference, UNIVERSAL::isa() will return undef. Don't bother doing a check twice.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: has it been blessed?
by rjray (Chaplain) on Mar 07, 2002 at 21:54 UTC

    The reason I wrote it that way is that ref($obj) is a single-opcode operation, much less expensive than the execution of UNIVERSAL::isa($obj, 'UNIVERSAL'). Unless you know for certain that the value being tested will a reference the majority of the time, then you can save a reasonable amount of execution time with ref() coupled with the short-circuiting and operator. I stand behind this one.

    --rjray

      That's a fair statement. It's always good to be efficient whenever it doesn't hurt readability. However, if you're optimizing for speed over readability, I feel that you're going to have problems.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: Re: Re: Re: Re: Re: has it been blessed?
by chipmunk (Parson) on Mar 08, 2002 at 05:21 UTC
    UNIVERSAL::isa($obj, 'UNIVERSAL') will also return true if $obj is the string 'UNIVERSAL', so the ref check is actually useful.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://150122]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-11-29 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?