[svn:perlfaq] r10878 - perlfaq/trunk

[email protected] Tue, 4 Mar 2008 16:28:37 -0800 (PST)
Newsgroups perl.cvs.perlfaq
Message-ID <[email protected]>
Author: comdog
Date: Tue Mar  4 16:28:36 2008
New Revision: 10878

Modified:
   perlfaq/trunk/perlfaq4.pod

Log:
* perlfaq4: How do I manipulate arrays of bits?
	+ iterate through array indices, not elements, to get the 
	right bit to set


Modified: perlfaq/trunk/perlfaq4.pod
==============================================================================
--- perlfaq/trunk/perlfaq4.pod	(original)
+++ perlfaq/trunk/perlfaq4.pod	Tue Mar  4 16:28:36 2008
@@ -1730,8 +1730,8 @@
 
 	@ints = (...); # array of bits, e.g. ( 1, 0, 0, 1, 1, 0 ... )
 	$vec = '';
-	foreach(@ints) { 
-		vec($vec,$_,1) = 1 if $_;
+	foreach( 0 .. $#ints ) { 
+		vec($vec,$_,1) = 1 if $ints[$_];
 		}
 
 The string C<$vec> only takes up as many bits as it needs. For