[Israel.pm] how to get the data type of blessed object

Mikhael Goikhman migo at homemail.com
Tue Jul 13 11:03:08 PDT 2004


On 13 Jul 2004 20:29:38 +0300, Itamar Elem wrote:
> 
> how can i get the datatype(ARRAY,HASH,....) of blessed object

There is attributes::reftype solution, but you may do some other things.
Any object may still be tested using isa:

	print "is arrayref\n" if $object->isa('ARRAY');

And of course, if you didn't overload the stringify or match operators,
you may get the datatype of the object ('ARRAY', 'HASH' and so on) using:

	my ($datatype) = $object =~ /(\w+)\(/    or die;

The first parentheses are essential here to force the list context.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list