Skip to content

Instantly share code, notes, and snippets.

@andrewsolomon
Created November 12, 2018 22:34
Show Gist options
  • Save andrewsolomon/425dcb8e6168a73f2f09429754686158 to your computer and use it in GitHub Desktop.
Save andrewsolomon/425dcb8e6168a73f2f09429754686158 to your computer and use it in GitHub Desktop.
#!/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