develooper Front page | perl.perl5.porters | Postings from March 2020

Re: chained comparisons

Thread Previous | Thread Next
Sawyer X
March 20, 2020 13:31
Re: chained comparisons
Message ID:
Adding the following perldelta change to reflect this:

    =head2 Chained comparisons capability

    Some comparison operators, as their associativity, I<chain> with some
    operators of the same precedence (but never with operators of different

         if ( $x < $y <= $z ) {...}

    behaves exactly like:

         if ( $x < $y && $y <= $z ) {...}

    (assuming that C<"$y"> is as simple a scalar as it looks.)

    You can read more about this in L<perlop> under
    L<perlop/Operator Precedence and Associativity>.

(The text itself is from perlop, except the title of the change and 
pointing to perlop. I imagine this is the best way to reduce 
misrepresenting this change.)

On 3/18/20 10:25 AM, Sawyer X wrote:
> On 3/17/20 7:14 PM, Todd Rinaldo wrote:
>>> On Mar 13, 2020, at 9:03 AM, Sawyer X <> wrote:
>>> [Top posted]
>>> Unless I find more specific arguments for curtailing this behind 
>>> experimental status (ones that specifically address this code), I 
>>> think this can be added without an experimental flag.
>> My only concern is that if this code gets run on an older perl, the 
>> failure would be more obvious if it failed on use feature 'chained'; 
>> instead of the code itself.
>> $>perl5.30 -E' my ($a, $b, $c) = (1,2,3); say "ok" if($a < $b < $c)'
>> syntax error at -e line 1, near "$b <"
>> Execution of -e aborted due to compilation errors.
> This is the same case as the new syntax of "<<~". You can use it 
> without a feature flag and if you try to use it on an old version of 
> Perl, it simply doesn't work.
> It doesn't fit experimental and it doesn't need "use feature" protection.
> I think we're ready to merge it.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About