# No.23 Perl Sample (code key - 60) # Learning Perl: Count Characters 1(文字数を数える) # 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 $numCharacters += $#chars + 1 ; # don't forget to add 1 to the index } print "numCharacters\t$numCharacters\n" ;