in reply to Re^2: Perl5 Language Extension: Definedness-Triggered Shortcut Operators
in thread RFC: Perl5 Language Extension: Definedness-Triggered Shortcut Operators

And, explained by aaron_baugher, below:
C:\>perl -E "my $x = 0 ; say $x // 'true'; my $y = 1; say $y // 'true' +;$x = undef; my $a=$x // warn 'RHS evaluated'; say $a;" 0 1 RHS evaluated at -e line 1. 1
updated.
  • Comment on Re^3: Perl5 Language Extension: Definedness-Triggered Shortcut Operators
  • Download Code

Replies are listed 'Best First'.
Re^4: Perl5 Language Extension: Definedness-Triggered Shortcut Operators
by aaron_baugher (Curate) on Mar 17, 2012 at 13:49 UTC

    Isn't this because the precedence makes it:

    $x = undef; my $a=($x // warn 'RHS evaluated'); say $a;

    Since $x is not defined, // returns the right hand side, and the call to warn returns 1 (true) to report success.

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.