in reply to Techniques On Saving Memory
I thought of using substr to point inside a string, but it doesn't work; but the following gives some form of workaround:
Result:$x = "one\0two\0"; $b = pack "p", $x; # pointer to "one" $b .= pack 'I', 4 + unpack 'I', $b; # pointer to "two" = substr($x, 4) printf "length: %i\n", length $b; printf "%i %i\n", unpack "II", $b; printf "%s\n", $_ for unpack "pp", $b;
length: 8 2279940 2279944 one twoLike I said, $x contains the packed data, so don't move that around.
For unpacking a fixed length string, you can use "P12" for a 12 byte string, for example. Appending the following snippet to the above code, I get the following additional result:
printf "%s\n", $_ for unpack "P2P2", $b;
on tw
Note: the unpacked data is a copy of the data, not a reference into the same, original data.
|
|---|