On 16 October 2017 at 11:24, David Santiago <deman...@gmail.com> wrote:
>
> Hi.
>
> How can i have \r\n on my heredoc string when i run my script in linux?
>
> my $text=<<"END";
> This is one line
> This is another one
> Final line
> END
>
> When i print this var in my linux box, i get this:
> "This is one line\nThis is another one\nFinal line"
>
> However i want:
> "This is one line\r\nThis is another one\r\nFinal line"
>
>
> What's the best way of accomplishing this?
>
> I know that i can $text=~ s/\n/\r\n/; but i think it must be a better
> way...
>

It may help if you explain why you want this, people tend to want the
opposite behaviour.

However, depending on why, it may be simpler to just encode the \r
directly in the heredoc, as, after all, they're just strings.

#!perl
use strict;
use warnings;

use Data::Dump qw(pp);

pp <<"EOF";
Hello\r
World\r
EOF

____

"Hello\r\nWorld\r\n"


I'm not sure what this does on windows though.


-- 
Kent

KENTNL - https://metacpan.org/author/KENTNL

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to