in reply to Re^4: How to check if an array element reference exists or not
in thread How to check if an array element reference exists or not
You can use ref to figure out the type of a reference/object. In your case, it seems you don't want to print it if it's "SCALAR"; or maybe the other way round, you do want to print it if it's "HTML::ElementTable::DataElement".
if ( ref($row->[7]) eq "HTML::ElementTable::DataElement" ) { print $row->[7]->as_text; }
Update: a more generic way would be to use can() to directly test whether the method in question is available:
use Scalar::Util 'blessed'; if ( blessed($row->[7]) and $row->[7]->can("as_text") ) { print $row->[7]->as_text; }
can() can only be called on blessed references, though, so you'd need to use Scalar::Util... (unless you resort to ugly stuff like if ("$ref"=~/=/ and ...) ).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: How to check if an array element reference exists or not
by corpx (Acolyte) on Apr 14, 2010 at 10:05 UTC |