Disclaimer: cross-posted at StackOverflow.
In Perl5, I can quickly and easily print out the hex representation of the \r\n Windows-style line ending:
perl -nE '/([\r\n]{1,2})/; print(unpack("H*",$1))' in.txt 0d0a
update:To create a Windows-ending file on Unix, create a in.txt file with a single line and line ending. Then: perl -ni -e 's/\n/\r\n/g;print' in.txt. (or in vi/vim, create the file and just do :set ff=dos) /update
I have tried many things in Perl6 to do the same thing, but I can't get it to work no matter what I do. Here's my most recent test:
use v6; use experimental :pack; my $fn = 'in.txt'; my $fh = open $fn, chomp => False; # I've also tried :bin for $fh.lines -> $line { if $line ~~ /(<[\r\n]>**1..2)/ { $0.Str.encode('UTF-8').unpack("H*").say; } }
Outputs 0a, as do:
/(\n)/ /(\v)/
First, I don't even know if I'm using unpack() properly. Second, how do I capture both elements (\r\n) of the newline in P6?
In reply to Perl6: Capturing newline in a string by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |