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


in reply to Re^2: 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

It's like if-then-else, but the value of "then" or "else" is returned by the whole.
  • Comment on Re^3: How to print an array of multidimensional arrays with a for or foreach loop

Replies are listed 'Best First'.
Re^4: How to print an array of multidimensional arrays with a for or foreach loop
by tobyink (Canon) on Aug 11, 2014 at 08:02 UTC

    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;