Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^2: Annoying warnings...

by tlm (Prior)
on Jul 16, 2005 at 13:07 UTC ( #475439=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://475439]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2021-03-05 11:21 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (109 votes). Check out past polls.