( 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.
- Is the field fixed width or variable width.
- If the field is fixed width, how do you know how much of the field is the string?
- If the field is variable width, how do you know how many bytes the string is?
- What character encoding is used? (Did you really mean ASCII?)
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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.