gildir has asked for the wisdom of the Perl Monks concerning the following question:
I want to check if some reference (say $r) is blessed or not.
Is there some easy way to do it, except for cumbersome, ugly and non-general hack like this:
if (ref $r ne 'HASH' && ref $r ne 'ARRAY' && ref $r ne 'CODE' && ref $ +r ne 'SCALAR' && ref $r ne 'GLOB')
And another question: How do I get the real type of reference, even if it is blessed. I mean, that is I have an object $o of class Foo::Bar, ref $o allways returns Foo::Bar. How do I chcek if $o is blessed reference to HASH or to ARRAY or whatever?
I have been peeking into some modules around (Data::Dumper I think) and found only this ugly code
Is this the only way?my ($class,$type,$addr) = (overload::StrVal($r) =~ /^(?:(.*)\=)?([^=]* +)\(([^\(]*)\)$/);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is reference blessed?
by jeroenes (Priest) on Nov 23, 2001 at 14:58 UTC | |
by gildir (Pilgrim) on Nov 23, 2001 at 15:29 UTC | |
by tye (Sage) on Nov 26, 2001 at 10:38 UTC | |
Re: Is reference blessed?
by davorg (Chancellor) on Nov 23, 2001 at 15:02 UTC | |
Re: Is reference blessed?
by clintp (Curate) on Nov 23, 2001 at 22:02 UTC | |
Re: Is reference blessed?
by pike (Monk) on Nov 23, 2001 at 15:09 UTC | |
by gildir (Pilgrim) on Nov 23, 2001 at 15:33 UTC | |
Re: Is reference blessed?
by brycen (Monk) on Mar 26, 2010 at 02:23 UTC | |
by ikegami (Patriarch) on Mar 26, 2010 at 04:26 UTC |