in reply to Re: subroutines problem
in thread subroutines problem

i got this code but when i tested it i got no result: if ($ARGV[0] eq "add") { $rtn = add($ARGV[1]); print " The sum is $rtn"; } elsif ($ARGV[0] eq "multiply") { $rtn = multiply($ARGV[1]); print "ther prod is $rtn"; } sub add{ my ($sum); $sum=0; foreach $_(@_) { $sum +=$_; } return $sum; } sub multiply { my ($multiply); $product=0; foreach $_(@_) { $product+=$_; } return $multiply: } am i doing it right?

Replies are listed 'Best First'.
Re^3: subroutines problem
by NetWallah (Canon) on Jul 21, 2005 at 04:23 UTC
    Your sub add is OK, but multiply seems to be just a copy of add, so it will not multiply.

    You have also continued to ignore previous good advice, starting from mrborisguy's - You need 3 arguments to your program - the Operation to perform and at least 2 operands.

    We will continue to help you, and it is OK to post more code and questions here - in fact that is encouraged - but you need to show some effort, and regard for good advice.

         "Income tax returns are the most imaginative fiction being written today." -- Herman Wouk