Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Having unpacked your binary file file I not sure why you don't just pack it again. Also, if you are trying to rewrite a binary file, why do you add newlines when you print?

$ perl -e 'print pack q{v*}, 0 .. 31;' > spw1006361.bin $ ls -l spw1006361.bin -rw-rw-r--. 1 johngg johngg 64 Nov 29 22:43 spw1006361.bin $ hexdump -C spw1006361.bin 00000000 00 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 |......... +.......| 00000010 08 00 09 00 0a 00 0b 00 0c 00 0d 00 0e 00 0f 00 |......... +.......| 00000020 10 00 11 00 12 00 13 00 14 00 15 00 16 00 17 00 |......... +.......| 00000030 18 00 19 00 1a 00 1b 00 1c 00 1d 00 1e 00 1f 00 |......... +.......| 00000040 $ perl -Mstrict -Mwarnings -E ' > my @vals = do { > local $/; > open my $binFH, q{<}, q{spw1006361.bin} or die $!; > unpack q{v*}, <$binFH>; > }; > $_ *= 2 for @vals; > open my $binOutFH, q{>}, q{spw1006361.bin} or die $!; > print $binOutFH pack q{v*}, @vals; > close $binOutFH or die $!;' $ hexdump -C spw1006361.bin 00000000 00 00 02 00 04 00 06 00 08 00 0a 00 0c 00 0e 00 |......... +.......| 00000010 10 00 12 00 14 00 16 00 18 00 1a 00 1c 00 1e 00 |......... +.......| 00000020 20 00 22 00 24 00 26 00 28 00 2a 00 2c 00 2e 00 | .".$.&.( +.*.,...| 00000030 30 00 32 00 34 00 36 00 38 00 3a 00 3c 00 3e 00 |0.2.4.6.8 +.:.<.>.| 00000040 $

Note how the hexdump output shows the values 0 through 31 in each little-endian short of the file before modification and 0 through 62 after modification.

I hope this is helpful but perhaps I've misunderstood your requirement.

Cheers,

JohnGG


In reply to Re: pack/unpack binary file by johngg
in thread pack/unpack binary file by mark4444az

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (11)
    As of 2015-07-31 07:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (275 votes), past polls