stajich: you will need to add the flag -noclose => 1 option when initing the SeqIO object or else the filehandle is closed. But if you are going to do this, just move the initialization of the SeqIO object outside the loop.
Thanks stajich, it works ok now. But it will work with just adding the *-noclose=>1* flag. So this will just work fine:
I don't understand why we still need to move the initialization of the seqIO outside the loop?#!/usr/bin/perl -w use strict; use Bio::SeqIO; my $file = $ARGV[0]; open INFILE, "<$file" or die "$0: Can't open file $file: $!"; for (my $trial = 1; $trial <=2; $trial++) { seek(INFILE,0,0); print "Trial $trial\n"; my $i =1; my $in = Bio::SeqIO->new(-format => 'fasta', -noclose => 1, -fh => +\*INFILE); while( my $seq = $in->next_seq() ) { print $i++, " : ", $seq->seq(), "\n"; } }
In reply to Re^4: How to avoid using array in concatenating string of multiple lines
by monkfan
in thread How to avoid using array in concatenating string of multiple lines OR How To Read FASTA
by monkfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |