http://www.perlmonks.org?node_id=475439


in reply to Re: Annoying warnings...
in thread Annoying warnings...

A clearer way of doing the above without a block is simply to test $x for being true (since all refs are true) first...

Well, not quite. The code you proposed would still result in a warning if $x is 1, for example:

% perl -MScalar::Util=reftype -we '$x=1; my $y=($x and reftype $x eq q +(HASH))' Use of uninitialized value in string eq at -e line 1.
What needs to be tested is that the value returned by reftype $x is defined. So your solution should be cast as
...( reftype $x and reftype $x eq 'HASH' )...
or, two avoid the duplicate calls to reftype:
{ my $temporary_variable = reftype $x; ...( $temporary_variable and $temporary_variable eq 'HASH' )... }

Update: Fixed missing "$x and " in the one-liner.

the lowliest monk