Write a Perl program three_vowel_echo.pl that prints its command-line argument to standard output, similar to echo command in Shell, except arguments should be printed only if they contain 3 consecutive vowels.
Your program can assume vowels are there are 5 vowel {a, e, i, o, u} and their upper-case equivalents {A, E, I, O, U} Your answer must be Perl only. You can not use other languages such as Shell, Python or C.
You may not run external programs, e.g. via system or backquotes.
$ ./three_vowel_echo.pl Pompeii Rome Aeolian Florence
Pompeii Aeolian
$ ./three_vowel_echo.pl
$ ./three_vowel_echo.pl an anxious bedouin beauty booed an ancient zoologist anxious bedouin beauty booed
$ ./three_vowel_echo.pl abstemiously adenocarcinomatous Hawaiian Eoanthropus abstemiously Hawaiian Eoanthropus
Wh thi k i ki t i l t t d t t
When you think your program is working you can autotest to run some simple automated tests:
$ 2041 autotest three_vowel_echo
When you are finished working on this exercise you must submit your work by running give:
$ give cs2041 test07_three_vowel_echo three_vowel_echo.pl
Write a Perl program middle_lines.pl which prints the middle line(s) in a file.
If the file contains an odd number of lines it should print one line.
If the file contains an even number of lines it should print two lines.
If the file contains no lines it should print nothing.
You can assume one and only one file is given as argument and that it exists and it is readable.
For example:
$ cat odd.txt line 0 line 1 line 2 line 3 line 4$ ./middle_lines.pl odd.txt line 2$ cat even.txt line 0 line 1 line 2 line 3 line 4 line 5$ ./middle_lines.pl even.txt line 2 line 3$ ./middle_lines.pl /dev/null |
Your answer must be Perl only. You can not use other languages such as Shell, Python or C.
You may not run external programs, e.g. via system or backquotes.
When you think your program is working you can autotest to run some simple automated tests:
$ 2041 autotest middle_lines
When you are finished working on this exercise you must submit your work by running give:
$ give cs2041 test07_middle_lines middle_lines.pl
:
Print the Line(s) from Stdin With the Largest Number
Write a Perl program largest_numbered_line.pl that read lines from standardinput until end-of-input. It should then print the line(s) which contained the largest number.
You can assume numbers do not contain white space, commas or other extra characters.
You can assume numbers are only in decimal format.
You can assume numbers are not in scientific/exponential format.
Lines may contain multiple numbers and they may contain any number of any character between the numbers.
If the largest number occurs on multiple lines you should print all of the lines in the order they occurred.
If no line contains a number, your program should print nothing.
$ ./largest_numbered_line.plI spent $ 15.50 for 3.3 kg apples yesterday. 2000 is a leap year. Ctrl-D 2000 is a leap year. |
$ ./largest_numbered_line.pl two2 four4 eight8 sixteen16 1 sixteen-and-half 16.5 1 11 12 13 Ctrl-D 1 sixteen-and-half 16.5 1 |
$ ./largest_numbered_line.pl the quick brown f42ox4 9 42 2 4 1 2 3 4 42.0 no forty two last 42Ctrl-D the quick brown f42ox4 9 42 2 4 1 2 3 4 42.0 last 42 |
$ ./largest_numbered_line.pl a 0.01 b .5 c -0.9 Ctrl-D b .5 |
$ ./largest_numbered_line.pl a -.5 b -5 c 90 Ctrl-D a -.5 |
$ ./largest_numbered_line.pl I love programming in Perl but I like Python better. Ctrl-D |
Your answer must be Perl only. You can not use other languages such as Shell, Python or C.
You may not run external programs, e.g. via system or backquotes.
When you think your program is working you can autotest to run some simple automated tests:
$ 2041 autotest largest_numbered_line
When you are finished working on this exercise you must submit your work by running give:
$ give cs2041 test07_largest_numbered_line largest_numbered_line.pl
Reviews
There are no reviews yet.