Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: heredoc and carriers return

by gabrielsousa (Sexton)
on Oct 25, 2016 at 14:42 UTC ( #1174695=note: print w/replies, xml ) Need Help??


in reply to Re: heredoc and carriers return
in thread heredoc and Carriage return

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

Replies are listed 'Best First'.
Re^3: heredoc and carriers return
by LanX (Sage) on Oct 25, 2016 at 16:53 UTC
    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 ?

        Read http://perldoc.perl.org/perldata.html#Special-Literals, and Super Search for __DATA__ to find more details.

        In short, you add __DATA__ as a line by itself at the end of your script, and everything after that in your script is treated as a special file which you can access through the handle DATA; like STDIN and STDOUT, it's already available, and you don't even have to open(DATA, ...) yourself. To get it to do what you want (maintain the distinct CR and LF from the Win32 EOL), you will need to binmode DATA; before you read from the DATA filehandle, just like you would if it were an external file.

        __DATA__ is pretty cool. Make sure you read up on it -- there are lots of cool __DATA__ tricks lurking in the Monastery.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2021-09-28 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?