# No.24 Perl Sample (code key - 61) # Learning Perl: Count Characters 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 $numCharacters = 0 ; while(<>){ # this reads the default file line by line chomp ; # delete the end-of-line character @chars = split ("",$_) ; # split into characters foreach (@chars) { # process each character next if (/\W/) ; # skip if not alphabet, number, or underbar $numCharacters++ ; # increase character freq } } print "numCharacters\t$numCharacters\n" ;