[Vienna-pm] pseudo-bitmask to ints

Thomas Klausner domm at cpan.org
Tue Oct 23 07:59:27 PDT 2007


Hi!

On Tue, Oct 23, 2007 at 04:38:38PM +0200, ReneeB wrote:
 
> Deins und meins gemischt (funktioniert ganz gut):

yay! Und jetzt noch statt dem pack/unpack ein kleiner String-Eval Hack:

sub p2i {
    my ($todo,$done)=@_;
    return $todo if $todo !~ /\D/;
    $todo=[$todo] unless ref($todo) eq 'ARRAY';
    $done=[] unless $done;

    foreach my $string (@$todo) {
        my $one=my $zero=$string;
        $one=~s/\D/1/;
        $zero=~s/\D/0/;
        if ($one=~/\D/) {
            p2i([$one,$zero],$done) if $one=~/\D/;
        }
        else {
            push(@$done,map { eval "0b$_" } $one,$zero);
        }
    }
    return wantarray ? @$done : $done;
}

Eigentlich gehoerte hier wohl noch mehr input checking rein (zB explodierts bei
input wie 00?5)
Andererseits koennte man den Kern wohl noch recht nett golfen :-)

-- 
#!/usr/bin/perl                              http://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}


More information about the Vienna-pm mailing list