Firstly, start your code with use strict; and use warnings;. Secondly you might try indenting your code a bit so that it's easier to read. Thirdly, for string comparisons you want to use eq and not =~.
Lastly, I think mrborisguy is right on the money. You'll have to take three arguments from the command line. (An operation and two numbers.) If your (homework?) problem description says otherwise, that's do-able too.
(Note: code still badly broken, but better.)use strict; use warnings; if ($ARGV[0] eq "add") { $rtn = add($ARGV[1]); print "The sum is: $rtn"; } elsif ($ARGV[0] eq "multiply") { $rtn = multiply($ARGV[1]); print "The product is: $rtn"; } else { # error message goes here # argv[0] was neither add nor multiply } sub add { } sub multiply { }
Cheers,
Brent
In reply to Re: subroutines problem
by dorko
in thread subroutines problem
by newly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |