There's some real food for thought in your replies, thanks.
So if get the point, there is no easy way to test whether something can be treated as a hash ref (for instance) short of trying to do so. So the best way to test is to try and catch any exceptions that indicate failure.
If I want to verify membership in a class, I'd need to do something like:
# Option 1.
if ( eval { $foo->isa('Some::Class') } ) {
# Do stuff with Some::Class
}
# or Option 2.
use Scalar::Util;
if ( blessed $foo and $foo->isa('Some::Class') ) {
# Do stuff with Some::Class
}
Are there any big ugly problems with either option? I've tested both and they seem OK, but there's no point trying to learn a new habbit, if it's a bad one!
|