bowei_99 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my $major_length = 8552; my $val = 4; # this gives $result as 33, as expected .... my $result = ($major_length == 4800) ? 18 : ($major_length == 8552) ? 33 : 0; # this gives $result as 1, not 33. Makes sense, # since $val == 4 evaluates to 1. But, I want $result to # be assigned 33, based on the fact that $val == 4. $result = ($major_length == 4800) ? 18 : ($major_length == 8552) ? ($val == 4) : 33; # this is what I had originally; it gives $result as 1, # not 33. $result = ($major_length == 4800) ? 18 : ($major_length == 8552) ? ($val == 4) : 33 ? ($val == 1) : 18; # Putting in parens doesn't help either # this gives $result as 1 - but # I want it to equal 18 or 33... $result = ($major_length == 4800) ? 18 : ( ($major_length == 8552) ? ($val == 4) : ( 33 ? ($val == 1) : 18 ) ); print "$result\n";
-- Burvil
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: nested tabular ternary
by diotalevi (Canon) on Apr 11, 2006 at 01:15 UTC | |
by McDarren (Abbot) on Apr 11, 2006 at 01:42 UTC | |
by diotalevi (Canon) on Apr 11, 2006 at 02:09 UTC | |
by McDarren (Abbot) on Apr 11, 2006 at 02:35 UTC | |
by diotalevi (Canon) on Apr 11, 2006 at 03:52 UTC | |
by ikegami (Patriarch) on Apr 11, 2006 at 02:22 UTC | |
by McDarren (Abbot) on Apr 11, 2006 at 03:03 UTC | |
by ikegami (Patriarch) on Apr 11, 2006 at 03:53 UTC | |
|
Re: nested tabular ternary
by liverpole (Monsignor) on Apr 11, 2006 at 01:17 UTC | |
|
Re: nested tabular ternary
by Errto (Vicar) on Apr 11, 2006 at 01:26 UTC | |
|
Re: nested tabular ternary
by GrandFather (Saint) on Apr 11, 2006 at 01:40 UTC | |
|
Re: nested tabular ternary
by nedals (Deacon) on Apr 11, 2006 at 06:36 UTC |