Hi all,

I need to write a script which would carry tar.gz archive in itself, which upon running it will save to a file on filesystem.

This script will be run under Windows environment.

I've decided to use __DATA__ section in order to store file contents.

However, I cannot later read the whole contents. File which I write is binary (tried both .dll and .tar.gz), and both contain SUB symbol (Notepad++ shows it that way). As I understand, it is equal to Ctrl^Z, and perl treats it as EOF and stops reading rest of the DATA.

But I need the whole data to be read and written to file. Any ideas how that can be accomplished?

Here is sample code (I already tried like 20-30 different ways, all with the same result):

my $outfile = "$HF_DIR/binary_copy.dat"; open (OUTFILE, ">", $outfile) or die "Not able to open the file for wr +iting. \n"; binmode (OUTFILE); binmode(DATA); do { local $/; print OUTFILE <DATA>;} ; close (DATA) or die "Not able to close the file: DATA \n"; close (OUTFILE) or die "Not able to close the file: $outfile \n";

and at the end there is __DATA__ section, with all the binary data:

__DATA__ ..binary data....SUB character......binary data... ......

So, perl only reads and writes til the first SUB character. And I need it to read and write all of the data.

Any help would be very much appreciated! Thank you in advance...

UPDATE: I decided to use base64 encryption and now all works, thanks for all your help guys!

In reply to Perl stops reading __DATA__ when meeting SUB character on Windows by yfnecz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.