in reply to Re^4: Using pack to evaluate text strings as hexadecimal values
in thread Using pack to evaluate text strings as hexadecimal values
It doesn't give me a single format string that I can use to convert back and forth between "records" and "fields".
The "problem" is that you cannot have a single conversion that produces binary numeric data for internal math use, and also produces asciified hex string for display purposes.
It's the same as asking for a single printf format that will display an number as decimal and hex. It cannot be done.
The solution is to have two templates: 1 for internal packing and unpacking:
$templ = 'A4 v d';; @fields = ( 'fred', 12345, 123.456 );; $record = pack $templ, @fields;; print unpack $templ, $record;; fred 12345 123.456
And another for unpack a record for display purposes:
$templ2 = 'A4 H4 H16';; print unpack $templ2, $record;; fred 3930 77be9f1a2fdd5e40
There is simply no way to implement a single template that would server both purposes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Using pack to evaluate text strings as hexadecimal values
by jpl (Monk) on Mar 22, 2011 at 13:22 UTC | |
by BrowserUk (Patriarch) on Mar 22, 2011 at 13:58 UTC |