Reputation: 87
Running this code produces an error stating "readline() on closed filehandle SEQFILE at line 14." Previous searches have all commented on how one should put some type of conditional after open. Doing so just kills the program (i left it out so I could see why it didn't open). I would guess the deeper problem is why is it not opening my file?
#!/usr/bin/perl -w
#Ask user to point to file location and collect from the keyboard
print "Please specify the file location: \n";
$seq = <STDIN>;
#Remove the newline from the filename
chomp $seq;
#open the file or exit
open (SEQFILE, $seq);
#read the dna sequence from the file and store it into the array variable @seq1
@seq1 = <SEQFILE>;
#Close the file
close SEQFILE;
#Put the sequence into a single string as it is easier to search for the motif
$seq1 = join( '', @seq1);
#Remove whitespace
$seq1 =~s/\s//g;
#Use regex to say "Find 3 nucelotides and match at least 6 times
my $regex = qr/( ([ACGT]{3}) \2{6,} )/x;
$seq1 =~ $regex;
printf "MATCHED %s exactly %d times\n", $2, length($1)/3;
exit;
Upvotes: 4
Views: 28653
Reputation: 19
Also note that if you use a || instead of an "or" in the line like so:
open SEQFILE, $seq || die "Can't open '$seq': $!";
This will not work correctly. See Link:
Upvotes: 0
Reputation: 57
Mismatch between where you are running your program from and where the 'file to open' is stored.
this is where i found it, Perl Readline on closed filehandle - file does not exist error
Upvotes: 0
Reputation: 183201
To see why open
is failing, change this:
open (SEQFILE, $seq);
to this:
open (SEQFILE, $seq) or die "Can't open '$seq': $!";
(See the perlopentut
manpage.)
Upvotes: 6