The first thing I notice looking at your code is that your method of populating the hash %sequences would appear to be inconsistent with your routines to parse the contents of the hash. When you read in the file, you count any line without spaces as a header and skip any lines composed entirely of spaces. That would mean that only lines with a mix of spaces and non-spaces would count as values. If you have no such lines, then your hash keys will always have undefined values. Consequently when you visit each key-value pair of the hash in the foreach statement) all of your split routines will be splitting an undefined value.

Now I do note that you expect spaces within the peptide chains portion of non-header lines. But is each and every header row followed by a row with a non-empty value for the peptide chains with at least one space?

Also it is a bit confusing that you are first splitting the non-header line ($value) using a colon ":" and then splitting the same non-header line using a pipe "|". Which is the actual field separator? Or were you intending to split the non-header line into fields using a colon and then split each field into subfields using a pipe? If so you need to move the line splitting each field to inside the foreach loop.

Of course, without any sample data it is hard to what non-header values are like. Perhaps you could provide some sample lines?

A further side note: you would do well to use different names for $value in your inner and outer loops. This makes reading your code confusing. It is also possible that you yourself might sometimes intend the meaning in the outer loop (the entire non-header row terminated by ";") and sometimes the meaning in the inner loop (the subfields created by splitting the row using ":").

Best, beth


In reply to Re: perl task3 by ELISHEVA
in thread perl task3 by huzefa

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.