in reply to testing defined($x) && length($x)
Building on the remarks from Bloodnok and ikegami, I think this does what you're asking:
if ( length( $x // '' ) {
Update: Oops, kennethk has informed me that I missed an important part of the question.
Maybe this is better, but maybe not:
if ( length( defined $x ? $x : '' ) ) {
|
|---|