Hi, I have issues designing a code that scans 2 DNA sequences (taken as input from user, of same length) and then compares the two sequences, nucleotide by nucleotide (e.g. compare nt 1 from sequence 1, with nt 1 from sequence 2 etc). I'm new to perl, I've tried several different ways but I don't seem to get anything working. With the code that I've tried, nothing is printed out at all, so the nested foreach loops seem to get stuck somewhere. I would be greatful for some help/advice. PS I know I should use script, I deleted all that to simplify my problem and will add all that later on once I figured out this problem. Code:
#!/usr/bin/perl use warnings; print("Please enter the first DNA sequence: "); $DNAsequence1 = <STDIN>; chomp($DNAsequence1); + $DNAsequence1=uc($DNAsequence1); $lengthDNA1=length $DNAsequence1; print("\nPlease enter the second DNA sequenc (of same length as the fi +rst): "); $DNAsequence2 = <STDIN>; chomp($DNAsequence2); + $DNAsequence2=uc($DNAsequence2); $lengthDNA2=length $DNAsequence2; #print "The length of DNA sequence 2 is $lengthDNA2"; if ($lengthDNA1==$lengthDNA2){ print "DNA sequence 1: $DNAsequence1\nDNA sequence 2: $DNAsequence2\n" +; } else { print "\nThe DNA sequences are not of same lenght, please try aga +in!"; } @DNAsequence1=split(//,$DNAsequence1); @DNAsequence2=split(//,$DNAsequence2); $score=0; foreach $base1 (@$DNAsequence1) print $score; { foreach $base2(@$DNAsequence2) { if($base1->[0] eq $base2->[0]) { $score += 3; print $score; } else { $score=$score+1; } } } print $score;

In reply to nested foreach loop, match DNA sequences and calculate score by NadjaPadjala

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.