haxmeister

Untitled

Nov 13th, 2023
2,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.92 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use v5.32.1;
  4. use strict;
  5. use warnings;
  6. use List::Util qw(sum product);
  7.  
  8.  
  9. # This function receives a list of numbers of any length
  10. # and returns the sum of these numbers
  11. sub addition{
  12.     return sum(@_) ;
  13. }
  14.  
  15. # This function receives a list of numbers of any length
  16. # and returns the product of all those numbers (multiply them all together)
  17. sub multiplication{
  18.     return product(@_);
  19. }
  20.  
  21. # This function receives a list of numbers of any length
  22. # and subtracts them each from the first number returning the result
  23. sub subtraction{
  24.     my $first_num = shift;
  25.     my $answer    = $first_num;
  26.  
  27.     foreach my $number (@_){
  28.         $answer = $answer - $number;
  29.     }
  30.  
  31.     return $answer;
  32. }
  33.  
  34. # This function receives 2 numbers as arguments
  35. # returns the result of dividing the first by the second
  36. sub division{
  37.     my ($first_num, $second_num) = @_;
  38.     return $first_num / $second_num;
  39. }
Advertisement