On Fri, 23 Dec 2005, Andrej Kastrin wrote: > 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 Here's one way to do it, or the skeleton of a way. You'll have to flesh out the details for yourself:
my $file = "whatever"; my @list = get_words_from( $file ); my %word_length; foreach my $word ( @list ) { $word_length{ length $word }++; } foreach my $count ( sort keys %word_length ) { print "Length: $count \t Words: $word_length{$count}\n"; } That or something like it should do what you're asking for. -- Chris Devers ¦Ñÿ²,s´>î
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>