Fast Way to Find Difference between Two Strings of Equal Length in Perl

前端 未结 4 1209
无人及你
无人及你 2021-01-03 01:20

Given pairs of string like this.

    my $s1 = \"ACTGGA\";
    my $s2 = \"AGTG-A\";

   # Note the string can be longer than this.

I would

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 02:02

    This is the easiest form you can get

    my $s1 = "ACTGGA";
    my $s2 = "AGTG-A";
    
    my @s1 = split //,$s1;
    my @s2 = split //,$s2;
    
    my $i = 0;
    foreach  (@s1) {
        if ($_ ne $s2[$i]) {
            print "$_, $s2[$i] $i\n";
        }
        $i++;
    }
    

提交回复
热议问题