ustd has asked for the wisdom of the Perl Monks concerning the following question:

Hi All: In one of my perl advertures, I have some binary data that comes to me from some CPAN library function which I store in a variable called $data If I hexify this binary data with: $hexstring = unpack "H*", $data; It performs this function correct, I verified my results against the unix commands: od -c and xxd -p :-) My question is how to I do the reverse operation to pack this data back into a $newdata variable ? I have tried various attempts to "pack" but I don't seem to know how to pack this correctly. I am stumbling on something. :-) Please help me to understand my packing errors ;-) Thanks!
  • Comment on Pack and Unpack binary data in a variable

Replies are listed 'Best First'.
Re: Pack and Unpack binary data in a variable
by stevieb (Canon) on Oct 28, 2015 at 16:30 UTC

    Welcome to the Monastery, ustd!

    Update: When you cross-post on other sites, it is polite to say you've done so. This reduces duplicate efforts.

    Please provide us with a sample of the original data you're working with.

    pack "H*", $var; should do the trick I would think.

      Thanks! It works! (I had posted here first, and then afterwords thought of posting on one other site also).
Re: Pack and Unpack binary data in a variable
by AnomalousMonk (Archbishop) on Oct 29, 2015 at 00:39 UTC

    See also perlpacktut.


    Give a man a fish:  <%-{-{-{-<