in reply to Working with Binary Numbers
Perl already has a nice built-in way to expand wildcards, it's called glob. It's just a simple matter of converting your wildcard syntax into one that glob recognizes.
Update: There is also an easier built-in way to convert them to integers from binary:my @data = qw( 000- 0101 011- 1-0- ); my @expanded = map { (my $s = $_) =~ s/-/{0,1}/g; glob($s) } @data;
my @integers = map { oct "0b$_" } @expanded;
blokhead
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Working with Binary Numbers
by akho (Hermit) on Sep 25, 2007 at 10:23 UTC | |
by shoness (Friar) on Sep 25, 2007 at 13:29 UTC | |
Re^2: Working with Binary Numbers
by salva (Canon) on Sep 25, 2007 at 13:55 UTC | |
by blokhead (Monsignor) on Sep 25, 2007 at 14:30 UTC | |
by salva (Canon) on Sep 25, 2007 at 14:50 UTC | |
by tye (Sage) on Sep 25, 2007 at 15:18 UTC | |
by ikegami (Patriarch) on Sep 25, 2007 at 15:19 UTC | |
by salva (Canon) on Sep 25, 2007 at 15:36 UTC | |
|
In Section
Seekers of Perl Wisdom