[Bioperl-l] how to break a while loop

chen li chen_li3 at yahoo.com
Sun Jan 8 11:26:59 EST 2006


Hi all,

I have a big file containing mutiple records. I just
need to read a few of them. I use the following code
(copy from Bio::SeqIO HOWTOs with small changes)but it
seems to me that it will never end untill the whole
file is read. My question: how do I break the loop?

Thanks,

Li

#!/usr/bin/perl
use warnings;
use strict;
use Bio::SeqIO;

# get command-line arguments, or die with a usage
statement
 my  $usage = "perl SeqIO_8.pl  infile infileformat
outfile outfileformat\n";
          my $infile = shift or die $usage;
          my $infileformat = shift or die $usage;
          my $outfile = shift or die $usage;
          my $outfileformat = shift or die $usage;
          my $filesize= -s $infile;
          print "\nThe file size is $filesize.\n";

 # create one SeqIO object to read in,and another to
write out
   my $seq_in = Bio::SeqIO->new('-file' => "<$infile",
                               '-format' =>
$infileformat);
   my $seq_out = Bio::SeqIO->new('-file' =>
">$outfile",
                                 '-format' =>
$outfileformat);

          # write each entry in the input file to the
output file
         my $count=0;
         while (my $inseq = $seq_in->next_seq){
                   $seq_out->write_seq($inseq);
                   $count++;

              print "\nThis is the record
number:$count\n";
              if ($count=10){exit;}# break a while
loop

               }



 exit;
                                    




		
__________________________________________ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 



More information about the Bioperl-l mailing list