develooper Front page | perl.perl5.porters | Postings from July 2016

[perl #36333] sort CONSTANT exhibits weird behavior

Thread Next
From:
Father Chrysostomos via RT
Date:
July 8, 2016 04:30
Subject:
[perl #36333] sort CONSTANT exhibits weird behavior
Message ID:
rt-4.0.18-27368-1467952191-1716.36333-15-0@perl.org
On Thu Jul 07 17:58:18 2016, dcollinsn@gmail.com wrote:
> It's being interpreted as a bareword for some reason?

Oh, what fun!  This is a very old bug.  And it occurs because of the way that the parser gets to decide whether the first token after ‘sort’ is a comparison sub or part of the list to sort.

The lexer (toke.c) assumes that any word immediately following ‘sort’ is a comparison sub, which gets emitted as a WORD token, just like a bareword.

It is the parser (perly.y) that distinguishes between these two:

    sort foo bar
    sort foo,bar

So the lexer does not actually know at the time whether the word will be a comparator or not.  That makes it hard to fix.

(All of this is from memory.  I may be getting some of it wrong.)

use constant{Just=>another=>Perl=>hacker=>};$\=",\n";
print join" ",map eval"sort $_,$_",qw!     Just Perl!

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=36333

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