Update: This assumes that the largest index in @pos is the length of your @bin array, which would work if you only needed to test for true/false on the array, indeed if you only need to test true/false then the second loop is unneeded as undef and 0 are both false ;)perl -e' @pos=qw(2 4 6 9); $max=0; for (0..(@pos -1)){ $bin[$pos[$_]]=1; $max=$pos[$_] if $max<$pos[$_]; } for (0..$max){ $bin[$_]=0 unless $bin[$_]; } print "@bin\n";'
In reply to Re: sequence of positions to binary sequence
by Utilitarian
in thread sequence of positions to binary sequence
by coldy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |