> vec() is a bit squirrelly.  In a nutshell (heh), vec views its first
> argument as a stream of bits taken from the string.  The third
> argument tells how many bits form a chunk.  8 bits gives chunks that
> can each have values from 0 to 255.  The second argument tells *which*
> chunk, numbering the chunks starting at 0.

so basically a bit twiddling on strings function ? :)

> 
> Probably the weirdest part of vec() is that it can be used both to get
> values, and set values (it's one of the four "lvalue" Perl functions).
> 
> So the quoted statement is looking at the scalar $output as a series
> of 8-bit chunks - essentially each character of the string.  And at
> the byte numbered length($output), which would be the byte just after
> the current end of the string, we're sticking a new 8-bit value.  This
> value is coming from computing the ascii value for the letter "E",
> which from memory is probably 68 or so.
> 
> In other words, that's just $output .= "E", the very hard way.

how about performance? i imagine vec() would be very fast for these
operations.

> 
> vec() is really good for a "boolean" array.  If you take the string
> 1 bit at a time, you can represent 0/1 or false/true with 1 bit
> per bit in the string.  vec($data, $n, 1) = 1 sets bit $n to 1,
> and vec($data, $n, 0) = 0 clears that bit.

i have seen this kind of thing done before. maybe i need to just start using
it.

> 
> vec() was added when Larry was thinking about what it would take to
> rewrite rn in Perl for Perl3.  He needed a way to hold the "already
> seen" article numbers for a newsgroup, and a simple array holding
> numbers into the 100,000s would have been far too fat and wasteful.
> 
> Hmm.  Maybe I need to do a column on this.  There might be some cool
> things there with the bit-ops as well.

that would be marvelous.


 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to