-
-
Save andrewsolomon/425dcb8e6168a73f2f09429754686158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Data::Dump qw/pp/; | |
my @neighbourhood = ( | |
{ | |
name => 'Donald', | |
age => 3, | |
behaviour => 'naughty', | |
stocking => [], | |
}, | |
{ | |
name => 'Theresa', | |
age => 5, | |
behaviour => 'nice', | |
stocking => [], | |
}, | |
{ | |
name => 'Angela', | |
age => 17, | |
behaviour => 'nice', | |
stocking => [], | |
}, | |
); | |
foreach my $person (@neighbourhood) { | |
next unless $person->{age} < 16; | |
if ($person->{behaviour} eq 'nice') { | |
push @{$person->{stocking}}, 'lollipop'; | |
} | |
else { | |
push @{$person->{stocking}}, 'coal'; | |
} | |
} | |
say pp(@neighbourhood); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment