in reply to Re: perl task...
in thread perl task...

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: perl task...
by graff (Chancellor) on Mar 08, 2009 at 18:09 UTC
    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:

    •  if ( /^>(\S+)/ ) {   ## remove the "$" at the end of the regex

    •      s/\s+$//;   ## instead of using "chomp"
    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.)
Re^3: perl task...
by apl (Monsignor) on Mar 08, 2009 at 12:48 UTC
    No our course matewrials just cover how to write the code...not to fix the errors
    So... have you talked to your professor?
Re^3: perl task...
by planetscape (Chancellor) on Mar 09, 2009 at 09:27 UTC
    No our course matewrials just cover how to write the code...not to fix the errors.....

    In my humble experience, writing the code IS fixing the errors... The two are inextricable, as ELISHEVA said.

    I do think you need to have a visit with your professor. Options such as getting a tutor may also be available for you.

    Good luck.


    Update: This Tutorial should also help: Basic debugging checklist. (Also added attribution, above.)

    HTH,

    planetscape