Advertisement
Codeprasa

Make Plural

Nov 5th, 2023 (edited)
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.03 KB | Source Code | 0 0
  1. #!/perl/usr/bin
  2. use warnings;
  3. use strict;
  4. use v5.32.1;
  5. use Data::Dumper qw(Dumper);
  6.  
  7.     my %pets = ( cat => 0,
  8.                  dog => 5,
  9.                  goat => 5,
  10.                  sheep => 0,
  11.                  cow => 3,
  12.                  pig => 4,
  13.                  Rooster => 1,
  14.                  Hen => 1);
  15.              
  16.         my $makePlural = "s";       # To make the plural words, s is appended to the end of the animal type.
  17.         my $pets = %pets;   # declare a scalar type variable out of the hash to make it easy to count the values of each    
  18.  pet category.
  19.         my $animalList;             # Declare a scalar type variable out of the hash to count pet types.
  20.         my $amountOfAnimals;        # Declare a variable to count the number of pets for the sake of comparing purpose.
  21.  
  22.         for(keys %pets) {  
  23.             $amountOfAnimals = $pets{$_};
  24.             $animalList = ucfirst($_);      # Make the first letter of each animal type uppercase. 
  25.                 if($amountOfAnimals > 1){
  26.                     say $animalList, $makePlural, "  ",$amountOfAnimals;
  27.                 } elsif ($amountOfAnimals == 1 or $amountOfAnimals == 0) {
  28.                     say $animalList, "   ", $amountOfAnimals;
  29.             }
  30.         }
  31.        
  32.        
  33.    
  34.        
  35.        
Tags: coding perl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement