|Do you know where your variables are?|
Is this reliable?by misterperl (Sexton)
|on Feb 18, 2013 at 16:26 UTC||Need Help??|
misterperl has asked for the
wisdom of the Perl Monks concerning the following question:
I want to do some conditional math. Without going into extensive explaination, I can't use a condtional statement.
So I'm attempting this in sort of an APL-ish approach:
# conditionally add 250 to the result iif $temp > 100;
my $temp = 150;
my $r = 1000;
$r += 250 * ( $temp > 100 );
I was pleasantly surprised to see this actually work correctly on my linux Perl 5.8.8 box, $r is 1000 unless $temp > 100 then its 1250. Perfect!
But what I wonder (and have my doubts about) is, will this appoach also work on a arbitrary Perl/OS implementation? My doubt is that ( $temp > 100 ) will consistently evaluate to 0 or 1 (as it does in APL, making it function perfectly for cases like this)..
Thank You wise ones.