Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

# Functionality: Script reads two command line arguments. # The two arguments mu

ID: 3869887 • Letter: #

Question

# Functionality: Script reads two command line arguments.

# The two arguments must be numeric and the first argument must be a

# value less than the second argument. If the arguments are valid,

# print the numbers between and including the numbers.

# Author: Bob D'Andrea

# Case #1: ./intlist.pl 3 6

#######################################

# Checks and enforces correct number of arguments

unless (scalar(@ARGV)==X){

   print "error: incorrect number of arguments",

   " ",

   "usage: intlist.pl a b (where a < b)",

   " ";

      exit X;

}

# Checks that first argument is smaller than second

if ($XXXX[0] >= $XXXX[1]){

   print "error: first argument must be less than second argument",

   " ",

   "usage: intlist.pl a b (where a < b)",

   " ";

      exit 1;

}

# prints arguments

else {

   $COUNTER=$ARGV[X];   # Sets counter to low integer

   # Prints integers until high integer is reached

   while($COUNTERXX$ARGV[1]){

      print $COUNTER;

         if ($COUNTERX$ARGV[1]){

            print ", ";

         }

         else {

            print " ";

         }

   $COUNTERXX1;

   }

}

exit 0;

Explanation / Answer

#! usr/bin/perl -w

use strict;

#Keyboard input from the users for $x and $y

print "enter two values ";

my $x=<STDIN>;

#chomp - This safer version of chop removes any trailing string that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR in the English module)

chomp($x);

my $y=<STDIN>;

chomp($y);

print "two values are $x,$y ";

my $mid;

#if first argument is greater than the second

if ($x<$y)

{

my $a;

for($a=$x;$a<$y;$a=$a+1)

{

   print "$a "; #Logic to get the values between the numbers passed from keyboard i.e. $x and $y

}

print " ";

}

else {

   print "$x is greater than $y ";

}

Sample O/p

perl middle.pl

enter two values

1

100

two values are 1,100

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

$perl middle.pl

enter two values

4

3

two values are 4,3

4 is greater than 3

Thanks for asking the question, Please let me know if you have any queries will be glad to help