# No.43 Perl Sample (code key - 46) # Learning Perl: Place each sentence in one line 1(センテンスを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 while(<>){ # this reads the default file line by line chomp ; # delete the end-of-line character my $text .= $_ ; # combine all the text into one line # use REGEX (regular expressions). Assuming that the period followed by an # upper case letter is the end-of-sentence symbol tr/\. ([A-Z])/\ \1/ ; # translate a period into a end-of-sentence tag
@sentences = split("\",$text) ; foreach (@sentences) { print "$_\n" ; } }