Hi monks, My problem is that given a DNA sequence is am trying to find all the pairs in it e.g. ATACG = AT TA AC CG. I have written a sub-routine that handles this fine. I am trying to extend the sub-routine so it calculates the frequency of each pair and sorts the pairs accordingly. However, what I have written makes no change to the output. Please could you try to point out my mistakes?! Any help is massively appreciated.
# snippet @pairs = get_nn_pairs (@segment1); sub get_nn_pairs { (@segment1) = @_; my $base; my $pair; my @pairs; my $i; my $nn_pair; # find and print all nn pairs form the sequence. foreach $i (1..$#segment1) { $base = $segment1[$i-1]; $pair = $segment1[$i]; @pairs = "$segment1[$i-1]$segment1[$i]\n"; # only seems to know the value of @pairs from inside foreach loop # problems start here. @pairs = split ('', $nn_pair); my %freq; foreach $nn_pair (@pairs) { {$freq{$_}++} } my @sorted_array = sort { $freq{$b} <=> $freq{$a} } keys %freq; print @sorted_array; } }

In reply to subroutine problem 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.