Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2020-10-30 20:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (284 votes). Check out past polls.

    Notices?