Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Masking part of a string

by ferreira (Chaplain)
on Jun 27, 2007 at 19:44 UTC ( #623720=note: print w/replies, xml ) Need Help??

in reply to Masking part of a string

I could not resist giving a functional and expensive solution to the problem with pairwise function from List::MoreUtils.

my $mask = '001111100'; my $str = 'AGACGAGTA'; my @mask = split( '', $mask ); my @str = split( '', $str ); my $masked = join '', pairwise { $a ? 'x' : $b } @mask, @str; print "Masked: $masked\n";
And now using regexes:
my $mask = '001111100'; my $str = 'AGACGAGTA'; my $masked = ''; while ( $mask =~ /\G(.)/gc ) { # walk the mask my $bit = $1; if ( $str =~ /\G(.)/gc ) { # walk the string to be masked $masked .= $bit ? 'x' : $1; } } print "Masked: $masked\n";

Probably it could be improved in space if mask is represented as a bit vector and there is an iterator to walk the mask just like $mask =~ /\G(.)/gc is doing.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2023-01-27 02:07 GMT
Find Nodes?
    Voting Booth?

    No recent polls found