Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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