[SOLVED] COMP9044 - Week 05 Weekly Test Questions

30.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

5/5 - (1 vote)

Sort Words Line by Line

Write a Perl program sort_words.pl that reads lines of text from its standard input and prints them to its standard output with the words on each line rearranged to be in sorted (alphabetic) order.

You can assume that a word is any sequence of non-whitespace characters.

You should print the words separated by a single space character.

For example:

$ ./sort_words.pl

I shall be telling this with a sigh

Somewhere     ages and ages hence

Two roads diverged in a   wood and I I took   the one   less traveled by

And that has made all the difference

Ctrl-D                         

I a be shall sigh telling this with Somewhere ages ages and hence

I Two a and diverged in roads wood

I by less one the took traveled

And all difference has made that the

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.

You can assume your input is ASCII.

No error checking is necessary.

 

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.