http://www.perlmonks.org?node_id=1096949


in reply to Re: How to print an array of multidimensional arrays with a for or foreach loop
in thread How to print an array of multidimensional arrays with a for or foreach loop

Hello ikegami,

I have seen several times this syntax (ref($row) ? @$row : $row) but I was not aware how it was operating. So I looked it up and I found ternary operator ? it was so simple [condition] ? [true expression] : [false expression].

Thank you for time and effort.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^3: How to print an array of multidimensional arrays with a for or foreach loop
by ikegami (Pope) on Aug 11, 2014 at 01:46 UTC
    It's like if-then-else, but the value of "then" or "else" is returned by the whole.

      Why the "but"? If-then-else also returns the value of "then" or "else". But if-then-else is parsed as a whole statement making it hard to use in an expression.

      use v5.14; # Ternary is convenient to use in an expression... my $value1 = int(rand 2) ? 666 : 999; # If-then-else is less convenient... my $value2 = do { if (int rand 2) { 666 } else { 999 } }; say for $value1, $value2;