raisputin has asked for the wisdom of the Perl Monks concerning the following question:
# $z is $x divided by $y, unless $y is zero, in which case $z should b +e zero too if ( $y == 0 ) { $z = 0; } else { $z = $x / $y; }
or more succinctly
$z = $y ? $x / $y : 0;
While I know that this works, I don't understand the construction. Probably because I am no brain surgeon, but hey, you don't start by performing quintuple bypasses either... :)
And I understand this even less.
and more succincly still, though thoroughly unreadable:
$z = $y && $x / $y;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Could someone please explain this to me in newbie terms :)
by kennethk (Abbot) on Aug 07, 2009 at 18:34 UTC | |
by Anonymous Monk on Aug 08, 2009 at 08:32 UTC | |
by Anonymous Monk on Aug 08, 2009 at 09:47 UTC | |
|
Re: Could someone please explain this to me in newbie terms :)
by moritz (Cardinal) on Aug 07, 2009 at 18:24 UTC | |
|
Re: Could someone please explain this to me in newbie terms :)
by raisputin (Scribe) on Aug 07, 2009 at 20:09 UTC |