Re: Usage of ref for testing if a passed in reference is a HASH, etc

[prev] [thread] [next] [Date index for 2004/11/12]

From: Yuval Kogman
Subject: Re: Usage of ref for testing if a passed in reference is a HASH, etc
Date: 21:16 on 12 Nov 2004
--7AUc2qLy4jB3hD7Z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Nov 12, 2004 at 13:51:23 -0500, Michael Henson wrote:
> Many places in Class::DBI use ref to determine if a given value is a
> reference to an array or a hash. Wouldn't it be better to use
> UNIVERSAL::isa, esp if the only purpose is to make sure that accessing a
> key makes sense?

What's the difference?

Personally I prefer Scalar::Util's reftype, just because it's easier
to figure out what the programmer was testing for without actually
reading into the line of code.

If you mean testing whether a /blessed/ reference is of the correct
class, not that a reference is to the correct data type, then
nonononononono!!! UNIVERSAL::isa is crummy. Called that way, that
is. ->isa is a method. Scalar::Util::blessed($thing) &&
$thing->isa('class') is the way to go.

--=20
 ()  Yuval Kogman <nothingmuch@xxxxxxxx.xxx> 0xEBD27418  perl hacker &
 /\  kung foo master: /me dodges cabbages like macalypse log N: neeyah!


--7AUc2qLy4jB3hD7Z
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBlShDVCwRwOvSdBgRAh4gAJ9dg5Y6HkeZN0Z+J4QugUPA4D/BIwCgjLJS
WH8w3rfWp4f1mLhRX/84BY0=
=aAgc
-----END PGP SIGNATURE-----

--7AUc2qLy4jB3hD7Z--

Re: Usage of ref for testing if a passed in reference is a HASH, etc
Yuval Kogman 21:16 on 12 Nov 2004

Generated at 17:31 on 15 Feb 2005 by mariachi v0.52