Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: When warnings get in the way

by davidrw (Prior)
on Apr 22, 2005 at 16:53 UTC ( [id://450484]=note: print w/replies, xml ) Need Help??


in reply to When warnings get in the way

The workaround seems fine -- it's straightforward and legible. You could probably make sure that $foo is never undef, too, so you don't have to worry about it. Something like:
my $foo = getFoo() || ''; if ($foo =~ /bar/ ){ ... }
But this has limitations (like if getFoo() returns 0).

side note #1 -- might just be your example, but treating foo as a boolean instead of string matching for "true" might work better, and avoids the warning. something like (again, depends on what getFoo() can return):
my $foo = getFoo() ? 1 : 0; if ( $foo ){ ... }

side note #2 -- I'm sure someone will mention it if it's true, but i think perl6 has some new operators that can handle things like that (but i might be mis-remembering).
Update: I was thinking of (found it here) this:
$a // $b; # short for: defined($a) ?? $a :: $b $pi //= 3; # so could do (of course perl6 only): if( $foo // '' eq "true" ){ ... } # or my $foo = getFoo(); $foo //= ''; if( $foo eq "true" ){ ... }

Replies are listed 'Best First'.
Re^2: When warnings get in the way
by ysth (Canon) on Apr 22, 2005 at 17:14 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2025-06-24 07:57 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.