in reply to Help with processing command line arguments
Now for the subroutines - $ARGV is not a built-in scalar, you just made it up. :P Try this instead for add:use strict; # always! my $op = shift; if ($op =~ /add/) { print "The sum is: ", add(@ARGV), "\n"; } elsif ($op =~ /multiply/) { print "The product is: ", multiply(@ARGV), "\n"; }
I'll leave multiply as an exercise. ;)sub add { my $sum = 0; $sum += $_ for @_; return $sum; } # and if that's too consise - try this one: sub add { my $sum = 0; foreach my $number (@_) { $sum = $sum + $number; } return $sum; }
Oh yeah ... you should take a look at Learning Perl.
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|