in reply to Re: Evaluating the condition ($x ||= $y)
in thread Evaluating the condition ($x)

Am I right?

Yes, I think so.
The problem is fixed by changing the troublesome rendition to:
($x) ? ($z = "true\n") : ($z = "false\n"); print $z;
I sure am glad I generally go for the extra bit of typing and use if/else. Bloody hell ... the amount of time I can spend in a ternary op rabbit hole ... :-(
Thanks harangzsolt33, Fletch, hv.

Cheers,
Rob

Replies are listed 'Best First'.
Re^3: Evaluating the condition ($x ||= $y)
by ikegami (Patriarch) on Aug 26, 2024 at 04:14 UTC
    say $x ? "true" : "false";

    And it's called the conditional operator. It is merely a ternary operator, just like addition operator is a binary operator. It not even Perl's only ternary operator.

      It not even Perl's only ternary operator.

      ???

        While it's Perl only infix ternary operators, Perl has circumfix ternary operators. dbmopen, for one.

        I would argue that the substitution and translate operators have three operands as well (pattern, replacement and flags).

Re^3: Evaluating the condition ($x ||= $y)
by tybalt89 (Monsignor) on Aug 26, 2024 at 07:53 UTC
    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11161348 use warnings; my $x = '1'; my $z = "undetermined\n"; ($x) ? print "true\n" : print "false\n"; ($x) ? $z = "true\n" : $z = "false\n"; print $z; # fewer parens :) $x ? $z = "true\n" : ($z = "false\n"); print $z; # my preferred version $z = $x ? "true\n" : "false\n"; print $z;