-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thanks to Jeff and George for help with my last question!
Now, say I make an instance as follows... { package Generic; sub MakeInstance { my $class = shift; my $name = shift; bless \$name, $class; } } { package MyClass; use base qw(Generic); } my $blessed_ref = MyClass->MakeInstance('my string'); Assuming I don't know .. how can I determine which class $blessed_ref was blessed into? I was thinking I could simply shift off the class using some method and return the result. That would produce something like "MyClass=REF(0xf00ba7)" which I could s/=\(\w+\)// to get the class name, but that seems like a horrible kludge to me (not to mention it may not work). Is there a better way? Next question. I want to make a series of methods to dereference instances for me automagically as follows... { package Generic; sub ReturnDeref { ref $_[0] ? Deref_($_[0]) : $_[0]; } sub Deref_ { if (ref($_[0]) eq 'SCALAR') { $$_[0] } elsif (ref($_[0]) eq 'ARRAY') { @$_[0] } elsif (ref($_[0]) eq 'HASH') { %{$_[0]} } # etc... for each ref type. } } The above *seems* to be okay (at least returns no errors, warnings or diagnostics). Where I'm having the trouble is when getting the data in and out as below... my @names_array = qw/ tom dick harry /; my $array_instance = MyClass->MakeInstance([EMAIL PROTECTED]); print ref $array_instance->ReturnDeref, "\n"; # \n is optional This is clearly wrong, since it prints nothing. I would have expected STDOUT like "ARRAY". What am I doing wrong? I'm guessing that instead of Generic->MakeInstance, I should perhaps have a Generic->BlessScalar, Generic->BlessArray, & Generic->BlessHash etc. But I was sort of hoping for a compact one-size-fits-all solution if that's possible. Any ideas? Am I on the right track or way off base or what? - -- ===================== Shaun Fryer ===================== http://sourcery.ca/ ph: 905-529-0591 ===================== Science is like sex: occasionally something useful comes out of it, but that's not why we do it. - -: Richard Feynmann -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (OpenBSD) Comment: http://sourcery.ca/sfryer-public_pgp_key.txt iD8DBQE/aPg12rKegHkuEpoRAuubAJ4lXLOr2+bbSsbO5E1UZmOlph4aYACcCEQq HKw4Yk1uGA+KESvdt9gemas= =uiPD -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]