Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Annoying warnings...

by tlm (Prior)
on Jul 16, 2005 at 13:07 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-25 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found