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

Re: chained comparisons

Thread Previous | Thread Next
From:
demerphq
Date:
February 6, 2020 02:53
Subject:
Re: chained comparisons
Message ID:
CANgJU+UT9UsgvZa1RmYet5+gT-eoDC59gfG0TL9EAouH5e9WbA@mail.gmail.com
On Thu, 6 Feb 2020 at 03:01, demerphq <demerphq@gmail.com> wrote:

> On Wed, 5 Feb 2020 at 08:50, Zefram via perl5-porters <
> perl5-porters@perl.org> wrote:
>
>> Branch zefram/cmpchain at <git://river.fysh.org/zefram/perl.git> may be
>> of some interest.
>>
>
> BTW, it was pointed out that this breaks some legal code, albeit weirdo
> stuff, for instance:
>
> sub foo {42} foo < $y > /bar/g
>

Hmm, it turns out your patch does NOT break this, it still deparses the
same way.

With chained relational operators:

$ ./perl -Ilib -MO=Deparse -wle'sub foo {42} if (foo < $fh > /bar/g) { 1 };'
Unquoted string "bar" may clash with future reserved word at -e line 1.
Unquoted string "g" may clash with future reserved word at -e line 1.
Name "main::fh" used only once: possible typo at -e line 1.
BEGIN { $^W = 1; }
BEGIN { $/ = "\n"; $\ = "\n"; }
Use of uninitialized value $cx in numeric ge (>=) at lib/B/Deparse.pm line
4591.
sub foo {
    42;
}
if (foo glob(' ' . $fh . ' ') / 'bar' / 'g') {
    use File::Glob ();
    '???';
}
-e syntax OK

Without:
$ perl  -MO=Deparse -wle'sub foo {42} if (foo < $fh > /bar/g) { 1 };'
Unquoted string "bar" may clash with future reserved word at -e line 1.
Unquoted string "g" may clash with future reserved word at -e line 1.
Name "main::fh" used only once: possible typo at -e line 1.
BEGIN { $^W = 1; }
BEGIN { $/ = "\n"; $\ = "\n"; }
Use of uninitialized value $cx in numeric ge (>=) at
/home/yorton/perl5/perlbrew/perls/perl-blead/lib/5.31.9/B/Deparse.pm line
4533.
sub foo {
    42;
}
if (foo glob(' ' . $fh . ' ') / 'bar' / 'g') {
    use File::Glob ();
    '???';
}
-e syntax OK

So maybe we dont need to do anything at all.

Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About