>>>>> "James" == James Kipp <[EMAIL PROTECTED]> writes:
>> vec( $output, length $output, 8 ) = ord "E"; James> is it just me or do others on this list have a tough time understanding the James> vec() function? 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. 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. 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. 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. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]