[Bioperl-l] how to break a while loop

Stefan Kirov skirov at utk.edu
Sun Jan 8 12:03:11 EST 2006


last
for example:
while (my $seq=$io->next_seq) {
....
last if ($count==10); #Use ==, not =
}
read a perl beginners ("Learning Perl" for example) book on perl syntax 
and operands (at least). It helped me a lot, it will help you.
Stefan

chen li wrote:

>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 
>
>_______________________________________________
>Bioperl-l mailing list
>Bioperl-l at portal.open-bio.org
>http://portal.open-bio.org/mailman/listinfo/bioperl-l
>  
>



More information about the Bioperl-l mailing list