in reply to unpack offset question
( Please avoid putting your entire post in code tags. Just put <p> at the start of every paragraph instead. )
You didn't specify byte order and whether the numbers are signed or unsigned.
@fields = unpack('n3', $_); # unsigned big-endian @fields = unpack('v3', $_); # unsigned little-endian @fields = unpack('S3', $_); # unsigned native @fields = unpack('n!3', $_); # signed big-endian @fields = unpack('v!3', $_); # signed little-endian @fields = unpack('s3', $_); # signed native
You provided even less information about the strings.
Update: n! and s! were introduced in 5.10. Pre 5.10,
# signed big-endian @fields = map { unpack 's', pack 'S', $_ } unpack('n3', $_); # signed little-endian @fields = map { unpack 's', pack 'S', $_ } unpack('v3', $_);
Update: Oops, had S for both signed and unsigned at the top. Thanks AnomalousMonk.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: unpack offset question
by magawake (Novice) on Mar 28, 2009 at 12:09 UTC | |
by ikegami (Patriarch) on Mar 28, 2009 at 18:55 UTC |