Let me give yall a better explanation of what i am trying to do, i already have the byte reversing done so no need to read a file backwards, but i can open both files before the byte reversal like this:
use File::Slurp; open my $in_file, '<', "file"; binmode($file); open ( my $out_file, '>', "reversed" ); binmode($out_file); my ( $buf, $data, $n, $bytes ); while (( $n = read $in_file, $data, 4096 ) != 0 ) { syswrite $out_file, pack( "v*", unpack("n*", $data )); $bytes+=$n; }

this above code will successfully read a file then byte reverse it to the other file, but you have to have a file on disk to do it.


now, what i want to be able to do, is open the $in_file, then byte reverse it in memory, and then write it to file after reversing it, or in other words, byte reverse the file in memory, then do whatever i want with it.


use File::Slurp; open ( my $in_file, '<', "file" ); binmode( $file ); my $temp; open my $mem_file, '>', \$temp; binmode( $mem_file ); my ( $buf, $data, $n, $bytes ); while (( $n = read $in_file, $data, 4096 ) != 0 ) { syswrite $mem_file, pack( "v*", unpack("n*", $data )); $bytes+=$n; } open ( my $out_file, '>', "reversed" ); binmode( $out_file ); syswrite ( $out_file, $mem_file );


i have tried a few different things and nothing has worked tho i am able to get the program to actually write the file, but it writes SCALAR(XXXXXXXX) or GLOB(XXXXXXXX) ect to the file and not the actual reversed data.

In reply to Re: Best way to read a file into memory and use normal operation on memory file? by james28909
in thread Best way to read a file into memory and use normal operation on memory file? by james28909

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.