I think getting one scalar out of a pair of arrays is going to give you one list (rather than the pair you want to compare). You can try this by adding a print $base line right inside the loop and seeing how many times it loops. Also, unless lines1 is an array of arrays, you want to get your character from it through a scalar like $lines1[0].

Depending on how good you are with perl you might find the following alternate too simple (or too c-like) but the foreach loop can replace the for loop (I think). And I never liked shifting.

# e.g @lines1 contains CACTATGAGTGATCGC and @lines2 contains # ACTGACTAATGCGTTG. @lines1= split(//,"CACTATGAGTGATCGC"); @lines2= split(//,"ACTGACTAATGCGTTG"); $line1length=@lines1; $line2length=@lines2; print ("1 :",@lines1,"\n"); print ("2 :",@lines2,"\n"); if ($line1length!=$line2length) { print "Length Mismatch\n"; } else { print "M :"; for ($x=0;$x<$line1length;$x++) { if ($lines1[$x] eq $lines2[$x]) { print $lines1[$x]; } else { print "*"; } } print "\n"; }

-- termix


In reply to Re: comparing strings by termix
in thread comparing strings by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.