in reply to Can unpack add zero bytes before converting?
I have not been able to come up with a way to do it in a single unpack, but if I post my solution maybe someone will come up with something better:
# Arguments are datum length (5, 6, 7, or 8) and stream data (whose # length must be a multiple of the datum length) sub unpack_stream { my ( $length, $stream ) = @_; $length ||= 5; $length >= 5 and $length <= 8 or die "Length $length must be between 5 and 8 inclusive\n"; my $pad = pack 'C*', ( 0 ) x ( 8 - $length ); return map { unpack 'Q<', "$_$pad" } unpack "(a$length)*", $stream +; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can unpack add zero bytes before converting?
by tybalt89 (Monsignor) on Sep 12, 2021 at 19:00 UTC | |
by Anonymous Monk on Sep 13, 2021 at 12:45 UTC |