Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: heredoc and carriers return

by LanX (Sage)
on Oct 25, 2016 at 13:47 UTC ( #1174692=note: print w/replies, xml ) Need Help??

in reply to heredoc and Carriage return

> 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.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: heredoc and carriers return
by gabrielsousa (Sexton) on Oct 25, 2016 at 14:42 UTC

    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
      Heredocs are not meant for binary data.

      If you don't want to read from an external file, then I can only see two options

      • try to put it after DATA and read from there (not tested)
      • encode and decode the stuff in an ASCII format, like base64

      HTH ! :)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        how i do it after DATA ?

        can you tell me how i use DATA ?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1174692]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2021-10-27 13:02 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (93 votes). Check out past polls.