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

[Fun With Perl] Puzzler (should this work?)



# This one seemed perplexing at the time...
#
# Does it work? If so, why? If not, why not?
# Should it work? What's going on?
#
# I posted this to comp.lang.perl.moderated about 6 months ago... it was
# politely suggested that the programmer try C :-)

# Original code

print "entry: ";
START: while(<STDIN>){
	chomp;
	$id = read_id_line($_);
	print "test id = $id\n";
     print "entry: ";
}

sub read_id_line() {
	shift;
	# >gi|319118|gb|L18858|L18858 MUSM1537RE Mouse
	if (/^>gi\|([0-9]+)[ |][.\n]*/) { return $1 }

	# >5H1A_HUMAN/53-400
	 if (/^>([0-9A-Z_]+)\//) { return $1 }

	# >Contig[0001], 825 bases, 8988 checksum.
	if (/^>Contig\[(\d+)\], /) {
		 $val = "contig$1";
		 return $val;
	}
	/^>(\w+)/;
	return $1;		#generic
} #read_id_line

-- --
        |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
  ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
       |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
      '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.org

==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org

</x-flowed>