It seems like you want something like this:
for ( 0 .. 32768 ) { print unpack( "B16", pack( "n", $_ ) ), "\n"; }
Of course that produces a LOT of output, but it will produce bitstrings in contiguous order, most significant digit at the 'left', and least significant at the 'right'.
One problem that it seemed like you were running into was the difference between ascending and descending bit order, combined with the difference between big-endian and little-endian packed integers.
There's some documentation on all this in pack, but a more thorough discussion in perlpacktut.
As for the question of why the iteration values in your foreach loop are being stringified, that can be explained in the documentation for unpack:
unpack does the reverse of pack: it takes a string and expands it out into a list of values. (In scalar context, it returns merely the first value produced.)
The key is that it treats its second arg as a string.
Dave
In reply to Re: unpack in incrementing variables
by davido
in thread unpack in incrementing variables
by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |