Write a Perl script that accepts exactly 2 integer arguments where the first arg
ID: 3837943 • Letter: W
Question
Write a Perl script that accepts exactly 2 integer arguments where the first argument must be less than the second argument (show your code below). The script will print a comma separated list of integers starting with the first argument up through the second argument. The last printed value must not be followed by a comma.
The intlist.pl script must be able to handle the following error situations:
Incorrect number of arguments and
The first argument is not less than the second argument (do not worry about trying to handle non-integer arguments).
The script file name must be: intlist.pl.
The script permission must be 705
Sample Output (provide yours in the same Word document)
Sunny Day Scenarios:
csis345@csis345-vm:~$ perl intlist.pl 3 13
3,4,5,6,7,8,9,10,11,12,13
csis345@csis345-vm:~$ perl intlist.pl -3 7
-3,-2,-1,0,1,2,3,4,5,6,7
Rainy Day Scenarios:
csis345@csis345-vm:~$ perl intlist.pl 4
error: incorrect number of arguments usage: intlist.pl a b (where a < b)
csis345@csis345-vm:~$ perl intlist.pl 13 3
The first argument must be less than the second argument usage: intlist.pl a b (where a < b)
Add at least 5 more scenarios in your Word document.
Explanation / Answer
if ( @ARGV != 2 )
{
print("error: incorrect number of arguments usage: intlist.pl a b (where a < b) ");
exit(1);
}
my $num1 = $ARGV[0];
my $num2 = $ARGV[1];
if($num1 > $num2)
{
print("The first argument must be less than the second argument usage: intlist.pl a b (where a < b) ");
exit(1);
}
print("$num1,");
for( my $a = $num1+1; $a <= $num2; $a = $a + 1)
{
print(",$a");
}
print(" ");
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.