unpack "N", $string will take the first 4 bytes of $string and return a 32-bit integer, taking the 4 bytes in "Network" order -- the first byte is the most significant, and then in descending order (ie big-endian).

unpack, "N*", $string will repeat the process of extracting 32-bit integers to consume all of $string, and returns a list of those integers.

my $cdrdata = unpack "N*", $string will unpack as many 32-bit integers as there are in $string, and then set $cdrdata to the first of them. Which, on the face of it, isn't what you wanted.

If the input is little-endian, you need unpack "V", ....

If the input is not 32-bit integers in one or other order, you need something more general, such as:

my $foo = reverse(unpack('h*', "\x21\x43\x65\x87\x09\xBA\xDC")), "\n +" ;
which sets $foo to the string: 1234567890abcd

You can, of course, replace the * in h* by a number to extract a fixed number of bytes. So '(h6)*' would extract six bytes at a time, as many times as it could.

I'll leave why this works as homework :-)


In reply to Re^3: How to reverse for each 2 character ? by gone2015
in thread How to reverse for each 2 character ? by bh_perl

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.