in reply to unpack - array takes too many bytes
The @twobytes array swallows all remaining bytes of the file, not just the 2 is am seeking.
You can use array slices to prevent the array from swallowing up more than you want:
my $data = "ABCDEFG"; my ($one, @two, @four); (@two[0..1], @four[0..3], $one) = unpack "C2 C4 C", $data; print "@two | @four | $one"; # 65 66 | 67 68 69 70 | 71
But note that assigning to a slice does not clear any other elements that might have been in the array.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: unpack - array takes too many bytes
by jjap (Monk) on Apr 15, 2011 at 04:58 UTC | |
by Eliya (Vicar) on Apr 15, 2011 at 05:36 UTC | |
by jwkrahn (Abbot) on Apr 15, 2011 at 06:11 UTC |