Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use v5.32.1;
- use strict;
- use warnings;
- use List::Util qw(sum product);
- # This function receives a list of numbers of any length
- # and returns the sum of these numbers
- sub addition{
- return sum(@_) ;
- }
- # This function receives a list of numbers of any length
- # and returns the product of all those numbers (multiply them all together)
- sub multiplication{
- return product(@_);
- }
- # This function receives a list of numbers of any length
- # and subtracts them each from the first number returning the result
- sub subtraction{
- my $first_num = shift;
- my $answer = $first_num;
- foreach my $number (@_){
- $answer = $answer - $number;
- }
- return $answer;
- }
- # This function receives 2 numbers as arguments
- # returns the result of dividing the first by the second
- sub division{
- my ($first_num, $second_num) = @_;
- return $first_num / $second_num;
- }
Advertisement