Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Refactoring: dumb or witty use of ternary operator?

by Abigail-II (Bishop)
on Jun 22, 2004 at 10:06 UTC ( #368656=note: print w/ replies, xml ) Need Help??


in reply to Re: Refactoring: dumb or witty use of ternary operator?
in thread Refactoring: dumb or witty use of ternary operator?

If the the value of $outhash{$str} is undefined, you'll get a warning about using an undefined value.
Are you sure about that? Can you show code giving the warning? If you can construct code that generates a warning when ++ is applied to an undefined value, make sure to report it as a bug, because that's not supposed to happen.
This would work equally well:
$outhash {$str} ||= 0; $outhash {$str} ++;
Yeah, but why bother? From the documentation about auto-increment and auto-decrement:
"undef" is always treated as numeric, and in particular is changed to 0 before incrementing (so that a post-increment of an undef value will return 0 rather than "undef").

Abigail


Comment on Re: Refactoring: dumb or witty use of ternary operator?
Select or Download Code
Re^2: Refactoring: dumb or witty use of ternary operator?
by cLive ;-) (Parson) on Jun 22, 2004 at 17:54 UTC

    "Are you sure about that?".

    No, obviously, but my guess is that his colleague made the same assumption that I did :)

    cLive ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2015-07-04 19:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls