# No.35 Perl Sample (code key - 38) # Learning Perl: Count words 2(単語数を数える) # 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 $numWords= 0 ; # define the global variables while(<>){ # this reads the default file line by line my @words = split ; # split $_ into each word; alternatively use split (" ",$_) foreach (@words) { # process each word $numWords++ ; # increase the count eveyr time # do something else on the word here } } print "numWords\t$numWords\n" ;