Fellow monks,
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
my ($class,$type,$addr) = (overload::StrVal($r) =~ /^(?:(.*)\=)?([^=]*
+)\(([^\(]*)\)$/);
Is this the only way?
I have considered perl an elegant language (when used correctly) a I do not like this.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.