No our course matewrials just cover how to write the code...not to fix the errors...

You are using a text editor to modify the code, aren't you? Do the course materials cover how to use the text editor? Perl comes with a lot of tools that everyone finds quite useful (and often adequate) to debug errors so that you know what needs to be fixed. I see no reason why the course materials should repeat all that information.

Check out the perldebug manual. Better yet, start your script like this:

perl -d name_of_your_script.pl
Then, at the first debugger prompt (DB<1>), type "h" for "help", then try stepping through the program with "n" (or use "s" at a subroutine call to step into that sub). After getting an input from a file, or a regex match or a split, use p $variable to look at what $variable contains, or p join "=  =", @array to see the elements of @array, and so on.

Also, it looks like you were unable to figure out what I was saying in your "perl task3" thread about using while (<DATA>) ... and  __DATA__ in your code. (And maybe you didn't understand what I was saying about the problems being related, and due to your data.) What I meant was:

# my $file = "P1GroupCExercise2_trypsin.txt"; # commented out ... # open(FILE,$file) or die "error: unable to open file $file\n"; # co +mmented out while (<DATA>) # not "<FILE>" { ... } ... __DATA__ >Protein:HEMINF_F3_Complement_N182_S1226717_L118 |Peptide:13|Missed:0|Type:I|Enzyme:trypsin|Seq:R| ...
Now, as for the problems you are still having, is there some chance that you are using a linux, unix or mac system, and the data is coming from a windows system (or from the web)?

In the while loop that reads your data from the file, try these two things:

That will make sure that carriage returns do not get in your way. When I did that on my mac (after fixing the DATA stuff), the script didn't issue any warnings. (But I don't know if it printed the intended output.)

In reply to Re^3: perl task... by graff
in thread perl task... 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.