Purchase Solution

Using $#ARGV in PERL, write a program that have two subroutines add() and multiply() that will add or multiply its arguments and print the result to screen.

Not what you're looking for?

Ask Custom Question

Write a program in PERL that have two subroutines add() and multiply() that will add or multiply its arguments and print the result to screen.

The values must returned from the add and multiply functions, back to the main program before the value is printed. The body of the code might look something like the following:

if ($ARGV[0] =~ /add/) {
$rtn = add($ARGV[1], ...]);
print "The sum is: $rtn";
}
elsif ($ARGV[0] =~ /multiply/) {
$rtn = multiply($ARGV[1], ...]);
print "The product is: $rtn";
}

sub add {
...
}

sub multiply {
...
}

(Hint: $#ARGV can be used to determine how many values were specified on the command line. The length of an array is also retrieved by writing something like $len = @ARGV.)

Purchase this Solution

Solution Summary

The solution uses $#ARGV in PERL to write a program that has two subroutines add() and multiple() that will add or multiple its arguments.

Solution Preview

The add() and multiply() subroutines take the two parameters and
perform the correct operation. The main code checks the number of
arguments to make sure it is correct and then uses the first one to
decide what operation to ...

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Basic Networking Questions

This quiz consists of some basic networking questions.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

C# variables and classes

This quiz contains questions about C# classes and variables.