in reply to How do I read a 24 bit integer?

Sorry. I have to repeat this here. It seems I can't go down enough levels to read even my own last reply. As I said, this code:
#!/usr/bin/perl -w use strict; my $myinput="\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06"; my($var1, $var2, $var3, $var4) = unpack('A3A3A3A3', $myinput); $var1 = unpack ('N', "\x00" . $var1); $var2 = unpack ('N', "\x00" . $var2); $var3 = unpack ('N', "\x00" . $var3); $var4 = unpack ('N', "\x00" . $var4); print "$var1\n"; print "$var2\n"; print "$var3\n"; print "$var4\n";
produces:
Use of uninitialized value in concatenation (.) or string at ./test2.p +l line 10. Use of uninitialized value in concatenation (.) or string at ./test2.p +l line 11. 66051 263430
When I would expect to see:
0 0 66051 263430

Replies are listed 'Best First'.
Re^2: How do I read a 24 bit integer?
by juster (Friar) on Jan 03, 2010 at 18:43 UTC

    Click on a note's title in order to show the responses beneath it.

    Pack mojo is always interesting and very deep! I found this in the pack manpage in order to explain your problem and BrowserUK's solution:

    When unpacking, "A" strips trailing whitespace and nulls, "Z" strips everything after the first null, and "a" returns data verbatim.