monkfan has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my $s1 = 'GATTACGAGTGGCGCTCGTGTAACGGCA'; my @ar = ('GATTACG','GCGCTCG','AACGGCA'); #21 (0,11,21) my @ar2 = ('GATTACG','TTACGAG','CGTGTAA'); #16 my @ar3 = ('TACGAGT','GTGGCGC','GCTCGTG'); #17 my @ar4 = ('GG','GG'); print append_n($s1,\@ar),"\n"; print append_n($s1,\@ar2),"\n"; print append_n($s1,\@ar3),"\n"; print append_n($s1,\@ar4),"\n"; sub append_n { my ( $str, $array ) = @_; my $nstring = "N" x length($str); foreach my $sbstr ( @$array ) { my $pos = index $str, $sbstr; substr ($nstring, $pos, length ($sbstr)) = $sbstr; } return $nstring; }
supposedly it should return :NNNNNNNNNNGGNNNNNNNNNNNNGGNNGATTACGNNNNGCGCTCGNNNAACGGCA #correct GATTACGAGNNNNNNNCGTGTAANNNNN #correct NNNTACGAGTGGCGCTCGTGNNNNNNNN #correct NNNNNNNNNNGGNNNNNNNNNNNNNNNN #wrong
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recovering Substrings to String with Gap (use m//g in scalar context)
by demerphq (Chancellor) on Apr 16, 2005 at 12:47 UTC | |
|
Re: Recovering Substrings to String with Gap
by tlm (Prior) on Apr 16, 2005 at 13:42 UTC | |
by tlm (Prior) on Apr 16, 2005 at 13:59 UTC | |
|
Re: Recovering Substrings to String with Gap
by salva (Canon) on Apr 16, 2005 at 11:07 UTC | |
by monkfan (Curate) on Apr 16, 2005 at 11:14 UTC | |
by salva (Canon) on Apr 16, 2005 at 12:03 UTC |