# No.44 Perl Sample (code key - 65) # Learning Perl: Place each sentence in one line 2(センテンスを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. # # modified version of Prof. Martin Chodorow's script # my $abbr ="(Mr|Mrs|Dr|U.S)"; # add more abbreviations while (<>){ chomp; $text .= "$_ "; #concatenate all the text } # if punctuation (.!?:) is followed by capital+small letters sequence, put an # end-of-line character $text =~ s/(^|[\.!\?\:])\s+([A-Z][a-z]|[A-Z]\s|$)/\1\n\2/g; # remove an end-of-line character if a sentence ends with abbreviation $text =~ s/(\b$abbr\.)\n/\1 /g; print "$text\n";