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.
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is this reliable?
by tobyink (Canon) on Feb 18, 2013 at 16:43 UTC | |
Re: Is this reliable?
by blue_cowdawg (Monsignor) on Feb 18, 2013 at 16:41 UTC | |
by AnomalousMonk (Archbishop) on Feb 18, 2013 at 16:59 UTC | |
Re: Is this reliable?
by frozenwithjoy (Priest) on Feb 18, 2013 at 17:11 UTC | |
Re: Is this reliable?
by aitap (Curate) on Feb 18, 2013 at 16:49 UTC | |
by misterperl (Pilgrim) on Feb 18, 2013 at 16:57 UTC | |
by tobyink (Canon) on Feb 18, 2013 at 17:13 UTC | |
by jethro (Monsignor) on Feb 18, 2013 at 17:18 UTC | |
by AnomalousMonk (Archbishop) on Feb 18, 2013 at 17:12 UTC | |
by aitap (Curate) on Feb 18, 2013 at 17:04 UTC | |
Re: Is this reliable?
by LanX (Saint) on Feb 19, 2013 at 10:56 UTC | |
by misterperl (Pilgrim) on Feb 19, 2013 at 16:05 UTC |
Back to
Seekers of Perl Wisdom