in reply to Re: comparing strings
in thread comparing strings

Thanks blokhead, But I am still having a few problems... I incorporated the snippet you gave me which works fine apart from it doesn't print the correct no. of *'s to correspond to the number of mismatches! This is what i did its slightly different from yours.
for ($dna_counter = 0; $dna_counter < $length_dna ; $dna_counter++ ) { if (substr(@lines, $_, 1) eq substr (@lines2, $_, 1)) { print ''; } else { print "*"; } } print "\n";

Replies are listed 'Best First'.
Re: Re: Re: comparing strings
by petral (Curate) on Oct 30, 2002 at 17:52 UTC
    Of course, if you're using arrays, you just need
    if ($lines{$_] eq $lines2[$_]) {
    The following will replace the non-matching chars in the string  $str1 with "*" (and leave the matching chars) by converting $str2 to a regex:
    $str2 =~ s/./(?:($&)|.)/g; print map{$_||'*'} $str1 =~ /$str2/


      p
Re: Re: Re: comparing strings
by graff (Chancellor) on Oct 31, 2002 at 04:47 UTC
    This is what i did its slightly different from yours.
    ... if (substr(@lines, $_, 1) eq substr (@lines2, $_, 1)) ...
    Well, that's actually way different from what Blockhead was doing -- he was using "substr()" on a scalar ($line); substr() is not supposed to be used on an array (@lines).