$var = pack "C2", 0x20, 0x30;
seems to work well enough, but now how do I address the elements of the array? Make changes to elements? In-place if possible. The pack/unpack semantics are not very friendly.
Currently I'm using substr($var, $index, 1, substr($var, $index, 1) + 10)
to add 10 to elements in-place.
And for intializers, if I need a 100 byte array of 0x20, what's the best way? $var = "\x20" x 100
works, is it the 'right' way?
two questions, two answers:
Q. seems to work well enough, but now how do I address the elements of the array?
A. vec() is your friend:
vec($var, $index, 8) += 10;
will do what you want.
Q. for intializers, if I need a 100 byte array of 0x20, what's the best way? $var = "\x20" x 100 works, is it the 'right' way?
A. it's OK in my book.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With