in reply to binary problem
The code below will do this, but rather than putting it into named variables like you say, it uses an array. One would have to use symbolic references (or an array of references that went to an arbitrary length) otherwise.
$str = '1000000000000100000000000000100'; while (($pos = index($str, '1', ($pos ? $pos + 1 : 0))) >= 0) { push(@length, length($str) - $pos - 1); $pos++; } for (1 .. @length) { print "\$var$_ would get $length[$_-1] bits\n"; }
When run, this gives me:
$var1 would get 30 bits $var2 would get 17 bits $var3 would get 2 bits
--rjray
|
|---|