Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Working with Binary Numbers

by ikegami (Patriarch)
on Sep 27, 2007 at 05:26 UTC ( [id://641276]=note: print w/replies, xml ) Need Help??


in reply to Working with Binary Numbers

Build your own "glob"... using the regex engine!
use strict; use warnings; my @data = qw( 000- 0101 011- 1-0- ); my ($re) = map "(?{''})(?:$_)(?{push \@results, oct \"0b\$^R\"})(?!)", join '|', map { local $_ = $_; s/([01]+)/(?{\$^R.'$1'})/g; s/-/(?:(?{\$^R.0})|(?{\$^R.1}))/g; $_ } @data; local our @results; { use re 'eval'; '' =~ /$re/ } local $, = ", "; local $\ = "\n"; print @results;

In this case, the generated regex is:

/ (?{''}) (?: (?{$^R.'000'}) (?:(?{$^R.0})|(?{$^R.1})) | (?{$^R.'0101'}) | (?{$^R.'011'}) (?:(?{$^R.0})|(?{$^R.1})) | (?{$^R.'1'}) (?:(?{$^R.0})|(?{$^R.1})) (?{$^R.'0'}) (?:(?{$^R.0})|(?{$^R.1})) ) (?{ $push @results, oct "0b$^R" }) (?!) /x

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://641276]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-20 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found