Description
You may not run external programs, e.g. via system or backquotes.
For example:
$ ./snap_n.pl 2 hi how are you hi
Snap: hi
$ ./snap_n.pl 2 hi hi hi hi hi hi hi hi hi hi hi hi
Snap: hi hi
$ ./snap_n.pl 4
Hello World Line 2
Hello World Line 3
Hello World Line 4
Hello World
Snap: Hello World
No error checking is necessary.
When you think your program is working you can autotest to run some simple automated tests:
$ 2041 autotest snap_n
When you are finished working on this exercise you must submit your work by running give:
$ give cs2041 test06_snap_n snap_n.pl
Write a Perl program, sort_file_lines.pl which is given one argument, a file name.
Your program should print the lines of the file in order of length, shortest to longest.
Lines of equal length should be sorted alphabetically.
You can asusme the lines in the file contain ASCII. Yoy should not assume anything else about the lines in the file.
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.
No error checking is necessary.
For example:
$ cat file.txt tiny short line medium line longgggggg line a equal line b equal line c equal line even longggggggggggggggggggggggggggggggggggggggggggerr
$ sort_file_lines.pl file.txt tiny short line medium line a equal line b equal line c equal line longgggggg line
even longggggggggggggggggggggggggggggggggggggggggggerr
When you think your program is working you can autotest to run some simple automated tests:




