Question

 Write a Perl script that accepts exactly 2 integer arguments where the first argument must be less than the second argument. The script will print a comma separated list of integers starting with the first argument up through the second argument.

 The last printed value should be the second command line argument not be followed by a comma.

 The script should also be able to handle the following errorsituations:

o incorrect number of arguments

o the first argument is not less than the second argument (don’t worry about trying to handle non-integer arguments)

 The script file name must be: intlist.pl

 The script must be located in $HOME/itec400/homework

 Make sure the permissions on the your itec400 directory are 705

 Make sure the permissions on your script are 705

Sample Output • Sunny Day Scenarios >intlist.pl 3 13 3,4,5,6,7,8,9,10,11,12,13 >intlist.pl -37 -3,-2,-1,0,1,2,3,4,5,6,7 Rainy

***Please use the template below - replace X***

#!/usr/XXX/XXX # Script names: intlist.pl # Case #1: ./intlist.pl <lower integer value> <higher integer> value # Check for th

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

unless($#ARGV+1==2){
print "error: incorrect number of parameters \n";
print "usage: intlst.pl a b (where a<b)\n";
exit;
}

if($ARGV[0] >= $ARGV[1]){
print "error: incorrect number of parameters \n";
print "usage: intlst.pl a b (where a<b)\n";
exit;
}
else{
$COUNTER=$ARGV[0];
while($COUNTER<= $ARGV[1]){
print $COUNTER;
if($COUNTER < $ARGV[1]){
print ", ";
}
else{
print "\n";
}
$COUNTER = $COUNTER + 1;
}
  
}

Output:

Command Line Arguments 15 Result CPU Time: 0.00 sec(s), Memory: 5284 kilobyte(s) 1, 2, 3, 4, 5

To change permissions of a directory of a file you can use below command:

chmod 705 <directory_name/file_name>

To change script permissions to 705 you can use the command: chmod 705 intlist.pl

Add a comment
Know the answer?
Add Answer to:
 Write a Perl script that accepts exactly 2 integer arguments where the first argument must...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem: Write a program that behaves as described below.If the first command-line argument after the program...

    Problem: Write a program that behaves as described below.If the first command-line argument after the program name (argv[1]) is “--help”, print the usage information for the program. If that argument is not “--help”, you are to expectargv[1]and subsequent arguments to be real numbers(C, integer, float, or double types)in formats acceptable to the sscanf()function of the C library or strings of ASCII chars that are not readable as real numbers. You are to read the numbers, count them and calculate the...

  • In this exercise, you will create a script called if_then_else.sh that uses an IF THEN ELSE...

    In this exercise, you will create a script called if_then_else.sh that uses an IF THEN ELSE statement. The if_then_else.sh script will Use one command line argument, which will be a number between 1 and 10 Assign the value of the first argument to a local variable called NUM. HINT: Look at line 5 in the example screenshot for arguments.sh Use one IF THEN ELSE statement to compare the value of NUM If the number is less than 5, display the...

  • Write a program that determines if a string (passed as a command-line argument) has all unique...

    Write a program that determines if a string (passed as a command-line argument) has all unique characters. The program must print the number of times each existing character appears, and then print whether or not they are all unique. Special requirements: You are NOT allowed to modify the input string or create any additional data structures (no arrays, lists, dictionaries, or other strings). You may have only one string (the one received as the command-line argument). You may have one...

  • (C++) Write a function that accepts an int array and the array’s size as arguments. The function...

    (C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...

  • Write a program in C or a script in bash, called “compare” that takes two numbers on the command line and compares them....

    Write a program in C or a script in bash, called “compare” that takes two numbers on the command line and compares them. The program should print the result of the comparison. Specifically, it should print “<x> is <comparison> <y>”, where <x> is the first number, <y> is the second number and <comparison> is one of “equal to”, “greater than” or “less than”. If the two numbers are equal, the program should have an exit status of zero. The exit...

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusi...

    Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string (‘A’<->’Z’, ‘B’<->’Y’, ‘C’<->’X’, etc). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before...

  • In this exercise, you will create a script called file_ops.sh that uses the various file operators...

    In this exercise, you will create a script called file_ops.sh that uses the various file operators The file_ops.sh script will Use one command line argument Use four IF THEN statement to compare the first command line argument Determine which file operators to use that produces the following output when the script run with the arguments shown WARNING: In the IF THEN statements, to avoid syntax error messages, there must be a space before and after each bracket and also between...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT