[an error occurred while processing this directive]

Perl

Menu

In-Class Assignment #3

In this ICA, you will search strings of text for specific patterns, capture those patterns (or parts of them), and modify the strings.

Enter a loop prompting the user for a string of text. Read in that text. Terminate the loop only if the text contains the word "done".

For each line of text, determine if the string contains:

  • A four-letter word (upper- or lower-case letters, nothing else), with spaces on either side. If so, print out that word (do not print the spaces)
  • A simple email address: letters followed by an @, followed by at least two groups of letters, each group seprated by a period. If so, print out the username and domain.
  • A five-digit number (no more, no less), with or without a comma after the second digit. If so, print out that number, without the comma.

For a bonus half-point, search the string for any of the four math operators: +, -, *, or /. If you find one, print out the entire string, after replacing that operator with its English equivalent ("plus", "minus", "times", or "divided by", respectively)

Sample I/O

To aid in my grading, please follow this format as identically as possible. Your output should exactly match the output (in bold) shown here, including all formatting and whitespace.

Please enter a string:
Do you know the muffin man?
four-letter word: 'know'
Please enter a string:
His address is muffin@cherry.lane.net.
address: user = 'muffin', domain = 'cherry.lane.net'
Please enter a string:
McDonald's: over 91,294 served each day.
four-letter word: 'over'
five-digit number: '91294'
Please enter a string:
I heard that 10000 people have @gmail.com addresses.
four-letter word 'that'
five-digit number: '10000'
Please enter a string:
lallip@rpi.edu is closed due to spam (it had over 54,100)
four-letter word: 'spam'
address: user = 'lallip', domain = 'rpi.edu'
five-digit number: '54100'
Please enter a string:
You'd better not find this number 100,000 as it's too big!
four-letter word: 'find'
Please enter a string:
keep in Mind that words can be either case, but must have spaces on either side!
four-letter word: 'Mind'
Please enter a string:
Realize th_t we're not using the Perl definition of a 'word'
four-letter word: 'Perl'
Please enter a string:
50,500 / 10 = 5,050
five-digit number: '50500'
50,500 divided by 10 = 5,050
Please enter a string:
0 * any number, even 89999, is still 0
four-letter word: 'even'
five-digit number: '89999'
0 times any number, even 89999, is still 0
Please enter a string:
lallip@cs.rpi.edu - cs. = lallip@rpi.edu
address: user = 'lallip', domain = 'cs.rpi.edu'
lallip@cs.rpi.edu minus cs. = lallip@rpi.edu
Please enter a string:
Add 4 cups of flour + 1 tsp of salt.
four-letter word: 'cups'
Add 4 cups of flower plus 1 tsp of salt.
Please enter a string:
Okay, I'm done now.
four-letter word: 'done'

The above sample input & output are available at ~lallip/perl/ic3input.txt and ~lallip/perl/ic3output.txt, respectively. You can use these files to test your script, like so:

./ica3.pl < ~lallip/perl/ic3input.txt > myoutput.txt
diff ~lallip/perl/ic3output.txt myoutput.txt

If the diff command returns no output, your code is working correctly. If it does, fix what's wrong. It will show lines from my file preceded with <, and corresponding lines from your file preceeded with >.

Submission Instructions

All submissions should be via solaris.remote.cs.rpi.edu. The RCS submission script has been deactivated. If you cannot access your CS Account, please see me.

To submit, please run ~lallip/public/submit.pl and follow the prompts. You may also provide the assignment and filename via the command line, rather than waiting for prompts. Read the documentation for the submission script by providing -? as a command line argument for more information.

You may submit infinite times, only the last submission is graded. Your final submission is due at the end of class today, 4pm, Wednesday February 18, 2010.

Perl Quotes
Perl Quotes