in reply to A good lesson on Tie (through a negative example)
Good post++
One words of caution though. If you take another look at my post at Re: sorting a vec, you'll find that I have replaced the code
print unpack '(B4)*', $vec;
With
print map{ vec( $vec, $_, 4) } 0 .. 99;
The reason is that the first example doesn't do what I originally thought, and not what I still think would be the most intuative reading of the code.
Using the unpack format '(B4)*', doesn't return every set of 4 bits from the string. It returns every other 4-bits from the string! That is, the output consists of a list of numbers, the value of each being determined from most significant 4-bits of each byte of the input string, with the other 4-bits being summarily discarded. (*)
Only noticed this a while after posting (I noticed that the string I had carefully packed 100 4-bit fields into was only outputting 50 values when printed with the original code).
This was changed within about 1/2 an hour of the original post, at a time when then CB was quiet, and there were only 8 people listed in others users. You must have grabbed the code pretty quickly after I posted the original.
I apologise for my error. I don't believe that this affects the information in your post, but if it does, feel free to transfer all the blame to me.
*It also worth noting that '(b4)*', also grabs the same, most significant, 4-bits of each byte, with the others being discarded -- but it starts processing the bytes in the string from the other end. Very confusing and non-intuative.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: A good lesson on Tie ( My error!)
by pg (Canon) on Nov 02, 2003 at 06:03 UTC |