Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: When warnings get in the way

by ambrus (Abbot)
on Apr 22, 2005 at 17:31 UTC ( [id://450506]=note: print w/replies, xml ) Need Help??


in reply to When warnings get in the way

You can turn on a certain kind of warning for a block or function, like

if (do { no warnings "uninitialized"; $foo eq "true" }) { ... }
IMO, there is nothing wrong with disabling a warning, as long as you do it only to certain warnings, not all (like no warnings;), and only for the part of code where the warning is ok. This is especially important with warnings such as no warnings "exiting"; for which there is no such easy way to avoid.

In this case however, I see nothing wrong with the explicit $foo && test, I do not think it is really bad. For a more comprehensible code, I'd write something like

if (defined($foo) && $foo eq "true") { ... }
or
if (($foo || "") eq "true") { ... }
or even
if ((defined($foo) ? $foo : "") eq "true") { ... }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2025-06-24 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.