[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] /^\s+(.*)/ && do { }



Huh. I'm not sure if I like this or not, but it sure is tight.

The basic idea is given a file format like this where there are an unknown number of ACCESSION entries on an unknown number of lines:

LOCUS BA000036 3309401 bp DNA circular BCT 19-MAY-2007
DEFINITION  Corynebacterium glutamicum ATCC 13032 DNA, complete genome.
ACCESSION   BA000036 AP005274 AP005275 AP005276 AP005277 AP005278 AP005279
           AP005280 AP005281 AP005282 AP005283
VERSION     BA000036.3  GI:42602314
PROJECT     GenomeProject:307

While reading through the file keep pushing only your array until /^\s+(.*)/ fails. At that point 'last'.

 if( /^ACCESSION\s+(\S.*\S)/ ) {
    push(@acc, split(/\s+/,$1));
    while( defined($_ = $self->_readline) ) {
       /^\s+(.*)/ && do { push (@acc, split(/\s+/,$1)); next };
       last;
    }
    $buffer = $_;
    next;
 }

I don't remember seeing a ' && do {} ' construct before... And I'm confused by $buffer, but that's a different battle. :)

j


Full source:
http://code.open-bio.org/cgi/viewcvs.cgi/bioperl-live/Bio/SeqIO/genbank.pm?rev=1.167&cvsroot=bioperl&content-type=text/vnd.viewcvs-markup