Similar to ref, but only returns the name if the item is a blessed class. In fact there are two subs, one for when you consider qr// constructs to be blessed/objects and one for when you don't. The reason the latter is provided is because a qr// is not really a user defined class type. For some uses this may be a required distinction (I have needed both at times).
Update: For most uses you are probably better off stealing GBARR's solution as posted by jmcnamara in a reply to this node. Thanks jmcnamara and gbarr. :-)
use overload; # required for either # qr// constructs are NOT considered blessed objects. sub blessed($) { (ref($_[0]) && (index(overload::StrVal($_[0]),'=')>=0) && overload::StrVal($_[0])!~/^Regexp=SCALAR/) ? ref($_[0]) : "" } # qr// constructs ARE considered blessed objects sub blessed($) { (ref($_[0]) && (index(overload::StrVal($_[0]),'=')>=0)) ? ref($_[0]) : "" }
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: blessed
by merlyn (Sage) on Dec 05, 2002 at 16:14 UTC | |
by demerphq (Chancellor) on Dec 05, 2002 at 16:25 UTC | |
by jmcnamara (Monsignor) on Dec 05, 2002 at 16:38 UTC | |
by demerphq (Chancellor) on Dec 05, 2002 at 20:26 UTC | |
by PodMaster (Abbot) on Dec 05, 2002 at 23:40 UTC |
Back to
Cool Uses for Perl