You are opening a file without testing if the open was successful. Add an 'or die..' and error message to your open statement so you will know if your open statement failed and have some clue why it didn't work.
Also, you are assuming your file contains only one line of data. In the following, I read and print in a loop while there are any records in the file that I have not already printed.
#!/usr/bin/perl
use strict;
use warnings;
# The filename of the file which contains the protein sequence
my $proteinfilename = 'NM_021964fragment.pep';#File is in my current working directory
#First open the file and associate a filehandle with it.
#For readability and more modern style lets name the filehandle $fh
#and use the 3-parameter version of the open statement.
open(my $fh, '<', $proteinfilename) or die "Failed to open $proteinfilename: $!";
print "Here is the protein:\n\n";
# Now we do the actual reading of the protein sequence data from the file,by using < > to get
# input from the filehandle. We store the data into variable $protein.
# In case there is more than one record in the file, read and print each
# record in a while loop.
while (my $protein = <$fh>){
#Print the protein onto the screen
print $protein;
}
#now that we got our data we can close the file
close $fh;
exit; d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159