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

Default EOL behavior might cause data loss #5082

Open
p6rt opened this issue Jan 24, 2016 · 1 comment
Open

Default EOL behavior might cause data loss #5082

p6rt opened this issue Jan 24, 2016 · 1 comment

Comments

@p6rt
Copy link

p6rt commented Jan 24, 2016

Migrated from rt.perl.org#127358 (status was 'new')

Searchable as RT127358$

@p6rt
Copy link
Author

p6rt commented Jan 24, 2016

From @Tux

$ dump crnl.csv
[DUMP 0.6.01]

00000000 31 2C 32 2C 2C 22 34 22 2C 22 35 20 77 69 74 68 1,2,,"4","5 with
00000010 20 5C 72 5C 6E 0D 0A 20 65 6D 62 65 64 64 65 64 \r\n.. embedded
00000020 22 2C 36 0D 0A ",6..

$ cat crnl.pl
use v6;
my $fh = open "crnl.csv", :r, :!chomp;
.perl.say for $fh.lines;

$ perl6 crnl.pl
"1,2,,\"4\",\"5 with \\r\\n\n"
" embedded\",6\n"

That first line should have been​:
"1,2,,\"4\",\"5 with \\r\\n\r\n"

as the \r is part of the data, not of an EOL

I need an option to leave every new-line sequence unchanged.

The nl attribute for open won't work, as I cannot know in advance what the EOL sequence in the stream/file is and besides, CSV allows mixed EOL, so «1,2,,4\r\n1,2,3,\r1,,3,4\n» is completely valid CSV for Text​::CSV

As callers to the parsing process are allowed to open an already opened file (an IO stream), this new :preserve-nl attribute (or whatever it will be implemented as), should be alterable *after* the stream has been opened, so it can be changed to local behavior inside the parsing proces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant