Hi guys, Thank you so much for the help and I really really appreciate what you guys did for me. I will definitely try all your suggestions plus those scripts. Good to be here and also learn a lot by reading emails on perl discussion. Regards, Changrong
On Wed, Dec 1, 2010 at 9:27 PM, Brian Fraser <frase...@gmail.com> wrote: > On Wed, Dec 1, 2010 at 4:58 PM, Mariano Loza Coll <malozac...@gmail.com>wrote: > Alternatively, a good samaritan out there can gelp you with a one or > two-liner code. > > If you only want to count letters, here's the 1-2 liner code, I guess: > >> #! /usr/bin/perl >> use strict; >> use warnings; >> use 5.010; >> >> my %letter_count; >> my %regex_count; >> my $total; >> >> while (<DATA>) { >> chomp; >> /(.)(??{ $regex_count{$1}++; $total++ })/g; #Using a regex >> >> for my $letter (split //) { #Using a for loop >> next if $letter =~ /\s/; >> $letter_count{$letter}++; >> } >> } >> >> printf "%s\t=>\t%f\n", $_, ($regex_count{$_} / $total) * 100 for sort keys >> %regex_count; >> >> >> __DATA__ >> >> MGSSKSKPKDPSQRRRSLEPPDSTHHGGFPASQTPNKTAAPDTHRTPSRSFGTVATEPKLFGGFNTSDTV >> TSPQRAGALAGGVTTFVALYDYESWIETDLSFKKGERLQIVNNTEGNWWLAHSLTTGQTGYIPSNYVAPS >> DSIQAEEWYFGKITRRESERLLLNPENPRGTFLVRESETTKGAYCLSVSDFDNAKGLNVKHYKIRKLDSG >> GFYITSRTQFSSLQQLVAYYSKHADGLCHRLTNVCPTSKPQTQGLAKDAWEIPRESLRLEVKLGQGCFGE >> VWMGTWNGTTRVAIKTLKPGTMSPEAFLQEAQVMKKLRHEKLVQLYAVVSEEPIYIVIEYMSKGSLLDFL >> KGEMGKYLRLPQLVDMAAQIASGMAYVERMNYVHRDLRAANILVGENLVCKVADFGLARLIEDNEYTARQ >> GAKFPIKWTAPEAALYGRFTIKSDVWSFGILLTELTTKGRVPYPGMGNGEVLDRVERGYRMPCPPECPES >> LHDLMCQCWRRDPEERPTFEYLQAQLLPACVLEVAE >> > > The regex solution uses the (??{CODE}) extended regular expression, > explained in perlre[0]. The for solution uses split with an empty pattern, > which splits on the empty string[1]. > > [0] http://perldoc.perl.org/perlre.html#Extended-Patterns > [1] http://perldoc.perl.org/functions/split.html > -- Changrong Ge, PhD student, Center for Biomembrane Research, Dept.of Biochemistry & Biophysics, Svante Arrheniusväg 16, Stockholm University, SE-10691 Stockholm, Sweden. Tel: +46-(0)8-16 24 87, Mobile: +46-(0)76-2176 119 Fax: +46-(0)8-16 2487, Email: changr...@dbb.su.se or changrong...@gmail.com