Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With chomping active, we lose a last empty line #4740

Closed
p6rt opened this issue Nov 9, 2015 · 7 comments
Closed

With chomping active, we lose a last empty line #4740

p6rt opened this issue Nov 9, 2015 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 9, 2015

Migrated from rt.perl.org#126598 (status was 'resolved')

Searchable as RT126598$

@p6rt
Copy link
Author

p6rt commented Nov 9, 2015

From @lizmat

$ 6 spurt("bar","\n"); dd open("bar").get
Str $var = Str # should be ""

$ 6 'spurt("bar","\n"); dd open("bar",​:!chomp).get'
Str $var = "\n"

@p6rt
Copy link
Author

p6rt commented Dec 30, 2015

From @smls

When called on a string, the .lines method ignores/chomps only *one* trailing newline, and treats all other newlines as line separators​:

  dd "\n\n\n".lines; # ("", "", "").Seq

However, when called on an IO​::Path or IO​::Handle, it ignores/chomps up to *two* trailing newlines​:

  spurt 'a', "\n\n\n";
  dd 'a'.IO.lines; # ("", "").Seq
  dd open('a').lines; # ("", "").Seq

Expected behavior​: All three examples should print ("", "", "").Seq.

@p6rt
Copy link
Author

p6rt commented Dec 30, 2015

From @lizmat

On 30 Dec 2015, at 17​:48, Sam S. (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Sam S.
# Please include the string​: [perl #​127092]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127092 >

When called on a string, the .lines method ignores/chomps only *one* trailing newline, and treats all other newlines as line separators​:

dd "\n\n\n".lines; # ("", "", "").Seq

However, when called on an IO​::Path or IO​::Handle, it ignores/chomps up to *two* trailing newlines​:

spurt 'a', "\n\n\n";
dd 'a'.IO.lines; # ("", "").Seq
dd open('a').lines; # ("", "").Seq

Expected behavior​: All three examples should print ("", "", "").Seq.

This is really RT #​126598 .

The problem is really that with auto-chomping (which is the default), the EOF flag is set when the last line of the file has been read. If that line is empty, however, IO​::Handle.get cannot see the difference between a “real” end of file and an empty line (because the eol delimiter has already been removed). It was felt that it would be better to lose an empty line at the end, then adding one that isn’t there.

This will require a fix in MoarVM.

Liz

@p6rt
Copy link
Author

p6rt commented Dec 30, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 26, 2017

From @zoffixznet

On Mon, 09 Nov 2015 07​:14​:47 -0800, elizabeth wrote​:

$ 6 spurt("bar","\n"); dd open("bar").get
Str $var = Str # should be ""

$ 6 'spurt("bar","\n"); dd open("bar",​:!chomp).get'
Str $var = "\n"

Thank you for the report. This is now fixed.

Fix​: rakudo/rakudo@f2fca0c...41bb137
Test​: Raku/roast@df5a84334d

@p6rt
Copy link
Author

p6rt commented May 26, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed May 26, 2017
@p6rt
Copy link
Author

p6rt commented May 26, 2017

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt added the IO label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant