http://qs1969.pair.com?node_id=641274


in reply to Working with Binary Numbers

Just for fun, the first solution that came into my head. It's not the most efficient (I agree with the use of glob as a practical solution) but I think it's reasonably simple to understand. No recursion, only iteration.
use strict; my @data = qw( 00- 0101 011- 1-0- ); while (grep /-/, @data) { @data = map do { unless (/-/) { $_; } else { my ($zero, $one); ($zero = $_) =~ s/-/0/; ($one = $_) =~ s/-/1/; ($zero, $one); } }, @data; } print join(" ", map oct "0b$_", @data), "\n";
Note that the grep can actually be removed if you don't mind having a 'map' with side-effects; you can keep track of whether you did any replacements as you go along, and stop after the first time that there weren't any.