Perhaps this help : use strict; my @text = qw/ hello world a ab abc abcde /; my @result ;
$result[ length $_ ]++ for ( @text ) ; for (1..$#result ) { print "$result[$_] for $_ chars char\n" if $result[$_] } # prints 1 for 1 chars char 1 for 2 chars char 1 for 3 chars char 3 for 5 chars char regards, Jim ----- Original Message ----- From: "Andrej Kastrin" <[EMAIL PROTECTED]> To: <beginners@perl.org> Sent: Friday, December 23, 2005 9:52 PM Subject: Distribution of words length > Hi, I'm totally confuse, while I haven't any idea how to solve my > problem. I have "n" lines text with one word in each line and I have to > make a frequency distribution of words length. > > If I have text: > hfdjhgsj #length=8 > abcabc #length=6 > adr #length=3 > bhvfgt #length=6 > vvv #lengt=3 > > So, the output of my parser shold be something like: > 8 1 # while there is 1 word 8 characters long > 6 2 # 2 words with 6 characters > 3 2 # ... > > I know that I should use hashes, but I have no idea where to start. > Thanks in advance for any pointers > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>