In-Class Assignment #4
Similar to last week's assignment, you will write a program which will determine if a series of paragraphs of text contain specific patterns.
Read paragraphs of text from the DATA pseudo-filehandle (see the
Debugging page for more information). Like in HW2,
you will set the $/ variable to "" to enable
paragraph mode. Continue reading from the DATA filehandle until a
paragraph contains the word "end", in any case. (Make sure it's the actual
word, not just the three letters being part of another word).
For each paragraph of text read in:
- Find all numbers (which could be either an integer or a floating point) that occur at the
start of any line of the paragraph. If the number is a floating point, you can
assume that it will have both an integer component and a fractional component.
(ie,
0.453is valid,.453and20.are not.) Print them all. - find all words (series of letters, no digits or underscores) containing exactly five letters, no more no less. These can occur anywhere in the paragraph. They are not necessarily surrounded by spaces. Print them out.
- Find all the sentences of the paragraph. A sentence is started by either the start
of the paragraph or two white-space characters, followed by a capitalized word. It includes all text
up to and including the first
?,., or!that is then followed by either two white-space characters or the end of the paragraph. For each sentence found, convert any newlines within to spaces, and print them out, one per line. Note that not every piece of text will be part of a valid sentence under these rules.
Sample I/O
You may copy and paste the following input to the __DATA__ marker in your script.
Your script should produce the bolded output below.
Okay, it is now 1:00pm, and I really need to get this sample text written. 60 students in the class are counting on me. Well, they're not really counting on me, they'd probably prefer to not have to do an ICA to begin with! Regardless, I'm going to give them one. And in order to do that, I need to create this sample text, don't I? Have you ever tried just creating text? Text that has to exist for the sake of there being text? It's not as easy as you might think! In fact, I have been doing this sort of thing for approximately 14 semesters now. And I'll tell you, it's probably the only 1 thing about being a teacher I truly dislike. It's not the grading 60 students assignments each week, or the holding office hours. No, it's definitely coming up with useless text to write. I am sorely tempted to just use an Ipsum Lorem generator to do this from now on! Where would the fun be in that, you might ask? Well I don't know! But I know it would be more enjoyable than this, that's for sure. On the other hand, if I did start using an Ipsum Lorem generator 13 times per semester, would that even work? Could I really get 12 or 13 good assignments out of text that I'm not designing? I don't know. Like this assignment, number 4, for example. I have to contrive the text so as to make sure that I put a floating point number like 3.14159 at the start of a line. And another floating point number such as 9.8 not at the start of the line, to make sure you don't match that. It's not as easy to remember these things as you might expect! And now I have 5 paragraphs (okay, note quite - after all, 1 of them is still in progress. That is probably enough, don't you think? I hope so, as my patience is ending. I am sure I have plenty of 5 letter words, and I know I have a WHOLE bunch of sentences. And there's at least a few numbers, yes? Yes. Oh, hey, there we go - a sentence containing only one word! Did you find it? I may need a vacation. End Scene. You shouldn't have anything from this paragraph. Remember, you're ending your program when a paragraph contains the word 'end' anywhere in it!
Output
As I requested last week, please endeavor to make your output match mine. Word for word, punctuation for punctuation, capitalization for capitalization. That will greatly help my grading of the assignment. Thank you.
Words: class, begin, going, order Sentences: Okay, it is now 1:00pm, and I really need to get this sample text written. Well, they're not really counting on me, they'd probably prefer to not have to do an ICA to begin with! Regardless, I'm going to give them one. And in order to do that, I need to create this sample text, don't I? Numbers: 14, 1, 60 Words: tried, exist, there, being, might, think, doing, thing, thing, about, being, truly, hours, write Sentences: Have you ever tried just creating text? Text that has to exist for the sake of there being text? It's not as easy as you might think! In fact, I have been doing this sort of thing for approximately 14 semesters now. And I'll tell you, it's probably the only 1 thing about being a teacher I truly dislike. It's not the grading 60 students assignments each week, or the holding office hours. No, it's definitely coming up with useless text to write. Words: Ipsum, Lorem, Where, would, might, would Sentences: I am sorely tempted to just use an Ipsum Lorem generator to do this from now on! Where would the fun be in that, you might ask? Well I don't know! But I know it would be more enjoyable than this, that's for sure. Numbers: 13, 12, 3.14159 Words: other, start, using, Ipsum, Lorem, times, would, Could, point, start, point, start, match, these, might Sentences: On the other hand, if I did start using an Ipsum Lorem generator 13 times per semester, would that even work? Could I really get 12 or 13 good assignments out of text that I'm not designing? I don't know. Like this assignment, number 4, for example. I have to contrive the text so as to make sure that I put a floating point number like 3.14159 at the start of a line. And another floating point number such as 9.8 not at the start of the line, to make sure you don't match that. It's not as easy to remember these things as you might expect! Numbers: 1 Words: quite, after, still, think, words, WHOLE, bunch, there, least, there Sentences: And now I have 5 paragraphs (okay, note quite - after all, 1 of them is still in progress. That is probably enough, don't you think? I hope so, as my patience is ending. I am sure I have plenty of 5 letter words, and I know I have a WHOLE bunch of sentences. And there's at least a few numbers, yes? Yes. Oh, hey, there we go - a sentence containing only one word! Did you find it? Words: Scene Sentences: I may need a vacation. End Scene.
Testing against the output
To test your program, run the following commands:
./ic4.pl > out.txt
diff ~lallip/perl/hw4output.txt out.txt
If the diff command returns any output at all, your program's output
doesn't match. Please address the differences and fix your code as needed.
Submission Instructions
To submit, please log on to solaris.remote.cs.rpi.edu and execute the
program ~lallip/public/submit.pl. You may submit infinite times, only
the last submission will be graded. Your final submission is due by 4pm today,
Thursday, February 25, 2010
