# New Ticket Created by "Carl Mäsak"
# Please include the string: [perl #119875]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=119875 >
<masak> rn: say "abc\n" ~~ /abc\n^^/ # why doesn't this match?
<camelia> rakudo 223075, niecza v24-95-ga6d4c5f: OUTPUT«Nil»
<moritz> rn: say "abc\n\n" ~~ /abc\n^^/
<camelia> rakudo 223075, niecza v24-95-ga6d4c5f: OUTPUT«「abc」»
<moritz> masak: because there is neither a line after the \n, nor the
start of the string
<masak> isn't the position at the end of my string the beginning of an
(empty) line?
<moritz> masak: an empty line would be "\n", not ""
<moritz> p5eval: "abc\n" =~ /abc\n^/m
<p5eval> moritz: No output
<masak> moritz: you're saying lines are \n-terminated, not \n-separated?
<masak> ...and whatever comes after the last \n is *not a line*?
<moritz> hm
<FROGGS> well, there is nothing
<moritz> p5eval: "abc\na" =~ /abc\n^/m
<p5eval> moritz: 1
<moritz> huh
<moritz> erm
<moritz> I call this inconsistent
<moritz> Perl 6 is consistent with Perl 5 here
<moritz> and both are inconsistent in themselves
<nwc10> I don't think that you should assume that Perl 5 is right, or good
<nwc10> just because it's been paying for the party for the past decade or two
<moritz> sure
<masak> well, of course.
<moritz> just wanted to check, because often p5 regexes behavior *is*
well thought-out
<masak> aye.
<masak> fwiw, I was parsing a file when all this struck me.
<masak> currently trying to make the grammar work against all the cases.
<masak> here's my mental model, fwiw: a "line" is any maximal run of
characters that don't contain a logical \n. thus ^^ at the end of a
string that finishes with a "\n", should match.
<moritz> agreed
<masak> in defense of this interpretation, I'd also like to point out
that there's absolutely nothing that says a (text) file has to end in
a "\n".
<masak> (and thus that final "\n" doesn't so much end the previous
line, as it begins a new one)
<moritz> there is something
<moritz> two decades of UNIX tradition
<moritz> (not saying that's valid, just that it exists)
<masak> indeed -- not contesting that there is tradition.
<masak> but I've also seen plenty of files not containing that final newline.
<masak> btw, all this reminds me about the special case put into Perl
5's &split.
<masak> feels like the same issue twice in slightly different guise.
<moritz> "the" special case? you mean there's just one? :-)
<masak> $ perl -E 'say for split /\|/, "a|b|c|"'
<masak> a
<masak> b
<masak> c
<masak> that one.
<masak> the one that says "the last delimiter doesn't count if there's
nothing after it".
<moritz> trailing empty elements are removed from split's output
<moritz> unless you add a -1 as limit
<masak> that's what I mean.
<masak> it doesn't happen for leading empty elements.
<masak> anyway, taking the delimiter as \n, we basically have our current case.
<masak> rn: .say for "a|b|".split('|')
<camelia> rakudo 223075, niecza v24-95-ga6d4c5f: OUTPUT«ab»
<masak> Perl 6 does *not* have the special case.
<masak> shouldn't for newlines in grammars either.
<FROGGS> masak: you have convinced me fwiw
* masak submits rakudobug