blessed v unblessed references

Randy J. Ray rjray at
Fri May 2 11:04:33 BST 2008

Dirk Koopman wrote:
> How do you safely tell whether a reference is blessed or not? When I say
> safely, I mean without the runtime aborting.

If you don't want to load Scalar::Util, there's something I call the "Can-Can
Test". Fortunately, you don't actually have to dance a Can-Can (you do have to
use the UNIVERSAL::* space, though):

	if (UNIVERSAL::can($ref, 'can')) # It's a blessed ref

Anything that's a blessed ref can call the method ->can. Unblessed references

Randy J. Ray      Sunnyvale, CA   rjray at

Silicon Valley Scale Modelers:

More information about the mailing list