Help for this page

Select Code to Download


  1. or download this
    my $op = shift @ARGV;
    if ( $op eq 'add' ) {
    ...
        my $rtn = multiply( @ARGV );
        print "The product is: $rtn\n";
    }
    
  2. or download this
    sub add {
        my $sum = 0;
    ...
        }
        return $sum;
    }
    
  3. or download this
    sub add {
        my $sum = 0;
        $sum += $_ for @_;
        return $sum;
    }
    
  4. or download this
    #!/usr/bin/perl --
    use strict;
    ...
    );
    
    $ops{$op}(@ARGV) if exists $ops{$op};
    
  5. or download this
    #!/usr/bin/perl --
    use strict;
    ...
        ( $result = 1, map { $result *= $_ } @ARGV );
    print ( $op eq 'add' ? 'The sum is:' : 'The product is:' );
    print " $result\n";