http://qs1969.pair.com?node_id=11130675

bliako has asked for the wisdom of the Perl Monks concerning the following question:

What happens when a ref is blessed into a non-existent class. Afterall bless's 2nd argument is a string and not a package qualifier.

bless [1,2,3] => 'nonexistent'

Some (irrelevant) info:

my use case is for "tagging" basic Perl data structures.

For example, a sub normally returns an arrayref. But in case of error it returns again an arrayref as: [code,errstr]. How can I differentiate the 2 cases? (Well the obvious way would be to create a proper Error class and return that in case of errors), but just for fun:

sub foo { if( $error ){ return bless [0, "error was ..."] => 'YouveGotError' } return [42,43] } my $ret = foo(); die "@$ret" if ref($ret) eq 'YouveGotError';

Thanks LanX for looking this up on CB and Corion for pointing to %main:: (I was looking in %INC)

2' Edit: here is another use-case for distinguishing between scalar(ref)s

sub fortunecookie { my $cookie = ...; if( ! $cookie ){ my $errstr = "failed to get a cookie because ..."; return bless \$errstr => 'YouveGotError' } return \$cookie } # ok a bit awkward with the stringref but it demonstrates that one can + do this with scalars too

blw bli ako