Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/perl/usr/bin
- use warnings;
- use strict;
- use v5.32.1;
- use Data::Dumper qw(Dumper);
- my %pets = ( cat => 0,
- dog => 5,
- goat => 5,
- sheep => 0,
- cow => 3,
- pig => 4,
- Rooster => 1,
- Hen => 1);
- my $makePlural = "s"; # To make the plural words, s is appended to the end of the animal type.
- my $pets = %pets; # declare a scalar type variable out of the hash to make it easy to count the values of each
- pet category.
- my $animalList; # Declare a scalar type variable out of the hash to count pet types.
- my $amountOfAnimals; # Declare a variable to count the number of pets for the sake of comparing purpose.
- for(keys %pets) {
- $amountOfAnimals = $pets{$_};
- $animalList = ucfirst($_); # Make the first letter of each animal type uppercase.
- if($amountOfAnimals > 1){
- say $animalList, $makePlural, " ",$amountOfAnimals;
- } elsif ($amountOfAnimals == 1 or $amountOfAnimals == 0) {
- say $animalList, " ", $amountOfAnimals;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement