On Thu, 24 May 2001 [EMAIL PROTECTED] wrote:

>I know, I know, this makes a grand total of three posted to the list in one
>day :-)
>
>I have what will usually be a list of objects, but on occasions nasty
>programmers (including me) do things to annoy me like inserting a hashref,
>so I end up with a data structure that looks like:
>
>  [
>    bless({}, 'Some::Class'),
>    bless({}, 'Some::Class'),
>    {},
>    bless({}, 'Some::Class'),
>  ]
>
>which as expected, makes things go crazy when I try to call a method on
>every object in the list.
>
>So what I really need is a surefire method to find out if something is blessed,
>rather than just a reference.  I know that I could do a simple regex against
>ref to find out if it is a HASH|ARRAY|SCALAR|CODE|REF|Regex, but a nice simple
>keyword like blessed( $svref ) would be nice.

ref

and I quote:

Returns a TRUE value if EXPR is a reference, FALSE otherwise.  If the
referenced object has been blessed into a package, then that package
name is returned instead.

my $wtf = ref $could_be_anything;

if ($wtf) {
        if ($wtf eq "HASH") {
        # Hash ref

        }
        else {
        # Object
        }
}

Cheers,
Mike
-- 
Mike Wyer <[EMAIL PROTECTED]>     ||         "Woof?"
http://www.doc.ic.ac.uk/~mw     ||  Gaspode the Wonder Dog
Work:  +44 020 7594 8440        ||
Mobile: +44 07879 697119        ||  ICQ: 43922064

Reply via email to