in reply to Working with Binary Numbers
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.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";
|
|---|