Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: heredoc and carriers return

by LanX (Saint)
on Oct 25, 2016 at 13:47 UTC ( [id://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 ?

        thanks
        can you tell me how i use DATA ?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-23 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found