help for a beginner!
Posted on 1997-12-08
I am a beginner of perl. I only know little bit about programming. I tried to write a perl program to cut up each paragraph into lines that has as many words as
possible. And the last line should be single spaced.
XXXXXXX. YYYYYY. YYYY,YYY. YYY,YYY. YYYY. ZZZZ.ZZZZ.
And I will get the output to another file like that:
XXXXXXX. YYYYYY. YYYY,YYY. YYY,YYY. YYYY. ZZZZ.ZZZZ.XXXX,XXXX.
here is the code I tried on my program, however, it don't work at all. I tried to look for some perl books for help. However, I just know which is good for me. Also, if you know which perl book is good for beginner, just let me know.
print "Input a file name:";
print "Type output file name:";
tr/\r//; #remove all the "\r" from the input file.
s/\n\s*\n////g; #replace empty lines with Tags
s/\n+//g; # remove newlines
s/\t+////g; # replace multiple tabs with nothing
s/\n\n\t/\t/; # remove new leading newline artifacts
s/$/\n/; # add newline at end
print OUT $_;