thanks for the reply. Apologies if this isn't clear I tried to keep it concise as possible so not to overload with code. This wasn't directly from my code so will paste a larger part see if it makes sense. The code is admittidely very ugly but its doing a very specific job. The @sequences is a list of two strings separated by a tab defined earlier still in the programme. @searchmotif is a short list of things to search for. I don't think I need to split the $temp3[0] into an array can just pattern match it but thought I'd leave this as it was written to see if it is clearer The larger bit of code is:

foreach my $line4 (@sequences) {my @temp3 = split ( '\t', $line4); my $counter = 0; my $paa = chop ($temp3[0]); my @fouraas = split ( '', $temp3[0]); if ($paa =~ /s/i ) {$pStotal++; foreach my $key (@searchmotif) {unless ( my @stemp = grep ( /$key/, @ +fouraas)){ push (@{$nsaminoacids{$key}},$temp3[1]);next;} #closes if +loop else { push (@{$saminoacids{$key}},$temp3[1]); next;} #closes if +loop } #close foreach loop } #closes if S loop elsif ($paa=~ /t/i ) {$pTtotal++; foreach my $key (@searchmotif) {if (my @ttemp = grep ( /$key/, @foura +as)){ push (@{$taminoacids{$key}},$temp3[1]); } #close +s if loop else { push (@{$ntaminoacid +s{$key}},$temp3[1]); } #close +s if loop } #close while loop } #closes if T loop elsif ($paa =~ /y/i ){$pYtotal++; foreach my $key (@searchmotif) {if (my @ytemp = grep ( /$key/, @foura +as)){ push (@{$yaminoacids{$key}},$temp3[1]); } #close +s if loop else { push (@{$nyaminoacids{$k +ey}},$temp3[1]); } #close +s if loop } #close while loop } #closes if Y loop else {push (@error, "$line4\tNot recognised p amino acid\n"); } } #closes foreach loop

i really don't understand why its not only using one of the actions after the unless command. This whole section if almost affectively just 3 repeats of what I posted ealier.


In reply to Re^2: Updating arrays within hashes by jonnyw83
in thread Updating arrays within hashes by jonnyw83

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.