Starting from:

$25

COMP9044 - Week 04 - Weekly Test Questions - Solved

Set up for the test by creating a new directory called test04, changing to this directory, and fetching the provided code by running these commands:

$ mkdir test04 

$ cd test04 

$ 2041 fetch test04 
Or, if you're not working on CSE, you can download the provided code as a zip file or a tar file.



Create A File of Integers In Shell

Write a Shell program, create_integers_file.sh which takes 3 arguments.

The first & second arguments will specify a range of integers.

The third argument will specify a filename.

Your program should create a file of this name containing the specified integers.

For example:

 

Your answer must be Shell. You can not use other languages such as Perl, Python or C.

You are not permitted to use the Linux program seq.


 

Write a Perl program, create_integers_file.pl which takes 3 arguments.

The first & second arguments will specify a range of integers.

The third argument will specify a filename.

Your program should create a file of this name containing the specified integers.

For example:

$ ./create_integers_file.pl 40 42 fortytwo.txt 

$ cat fortytwo.txt 

40 

41 

42 

$ ./create_integers_file.pl 1 5 a.txt 

$ cat a.txt 











$ ./create_integers_file.pl 1 1000  1000.txt 

$ wc 1000.txt 

1000 1000 3893 1000.txt 
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.

When you think your program is working you can autotest to run some simple automated tests:

$ 2041 autotest perl_create_integers_file 
When you are finished working on this exercise you must submit your work by running give:

$ give cs2041 test04_perl_create_integers_file create_integers_file.pl 
 

 

It will be given two arguments n and the file name.

Your program should print nothing if the file does not have an n-th line You can assume n is a positive (non-zero) integer.

You should not assume anything 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.



More products