in reply to sequence of positions to binary sequence
@bin[@pos] = (1) x @pos; #(undef, undef, 1, undef, 1, undef, 1, undef, + undef, 1)
That may be good enough, it depends on what you intend to do with @bin. To get the output you requested, follow the above with:
$_ ||= 0 for @bin; #(0, 0, 1, 0, 1, 0, 1, 0, 0, 1)
Update:
Or, you could do the whole lot in reverse (given your revised spec):
my @bin2 = (0) x 15; # assign 15 zeros @bin2[@pos] = (1) x @pos; # fill in the 1's
|
|---|