Back to labs/answer key page

You should end up with a file called bysent that contains something like this:

#!/usr/bin/perl

#Set perl to paragraph mode and multiline matches. 
$/ = "";   #paragraph mode
$* = 1;    #multiline matches

#Open the input file. 

open(INPUT, "senttest");

#Open the output file.

open(OUTPUT, ">senttest.out");

#While there are paragraphs in the input file, take them one at a time and: 

while (<INPUT>) {

#   Reformat them. 

    s/\n/ /g;     #replace all existing newlines with space
    s/\. /\.\n/g; #put a newline after all periods, and get rid of the extra space

#   Print them to the output file. 

    print OUTPUT; 
 
}                                       

#Close the input and output files.
close(INPUT);
close(OUTPUT);

Back to labs/answer key page

-----

Emily M. Bender
Last modified: Fri Dec 8 11:59:38 2000