# No.40 Perl Sample (code key - 43) # Learning Perl: List Sorted Words (ソートした単語を並べる) # Tomonori Nagano # Last Update: January 18, 2008 # # This file is encoded in Unicode (UTF-8). If you see gibberish characters, # please re-encode the file in utf-8. # # this sample script is simplified for pedagogical purposes. Those who are # interested in advanced Perl programming are encouraged to consult with # relevant sections of "Perl Cookbook" by Christiansen & Torkington my $numTypes = 0 ; while(<>){ # this reads the default file line by line chomp ; # delete the end-of-line character s/([^\- a-zA-Z0-9])/ \1 /g; # a negative definition of punctuation @words = split (" ",$_) ; # split into words foreach (@words) { # process each word $seen{$_}++ ; # create a hash of seen words } } foreach my $key (sort keys %seen) { print "$key\t$seen{$key}\n"; }