Re: heredoc and carriers return
by choroba (Cardinal) on Oct 25, 2016 at 09:35 UTC
|
I can confirm the behaviour in 5.25.5 (built on September 16) on Linux.
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
my $nix = << '__NIX__';
line 1
line 2
__NIX__
my $win = << '__WIN__'; # ^M present at end of lines.
line 1
line 2
__WIN__
# ^M present here, too:
my $quoted = 'line1
line2
';
say /\r/ for $nix, $win, $quoted;
I can't find it documented anywhere.
Update: It doesn't work for normal quoted strings, either.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
| [reply] [d/l] [select] |
|
|
| [reply] |
|
|
| [reply] [d/l] |
|
|
Neither open nor encoding describe how they influence Perl's parsing of multiline string literals.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
| [reply] [d/l] |
Re: heredoc and carriers return
by shawnhcorey (Friar) on Oct 25, 2016 at 11:09 UTC
|
my $win = << "__WIN__";
line 1\r
line 2\r
__WIN__
Using a double quote around the heredoc tag will cause the heredoc to be interpolated. That is, the "\r" will be interpolated as a CR (U+000D). | [reply] [d/l] |
Re: heredoc and carriers return
by LanX (Saint) on Oct 25, 2016 at 13:47 UTC
|
> heredoc read the LF ( \n ) , but dont parse / stores the carriers return ( \r )
there is a misconception on your side and probably it's an XY Problem too.
\n is the newline according to the OS you use and NOT (only) the LF from ASCII.
When you print "some line break \n and more lines" then Perl will autotranslate the \n to whatever *nix, win or mac wants to see.
Perl does it to assure maximum OS independency.
You are probably bitten by the reverse effect, that some combinations of CR and LF are interpreted as \n.
The answer to your problem is asking what for do you need it?
If you just need linebreaks ignore the effect, if you need the \r otherwise, do like suggested and include them explicitly.
You are free to put the text into an external file and read it in binmode , or even encode it as hex or base64 if you really need literally the same ascii code.
| [reply] [d/l] |
|
|
i have a pdf file / binary inside my perl script using heredoc
has 40 Carriage returns, i can search on VI, i see the ^M
but when i print to a file i lose all Carriage returns..
i'm assuming is a problem of heredoc
| [reply] |
|
|
| [reply] |
|
|
|
|
|
|
|
Re: heredoc and Carriage return
by choroba (Cardinal) on Oct 25, 2016 at 20:38 UTC
|
Crossposted to reddit.
Please, next time link to your crosspost yourself, to avoid duplicate effort by people not attending both sites.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
| [reply] [d/l] |
|
|
> to avoid duplicate effort by people not attending both sites
Indeed! :/
| [reply] |