Instantly share code, notes, and snippets.

@andrewsolomon /map.pl Secret
Created Nov 12, 2018

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 => [],
},
);
map {
push @{$_->{stocking}},
$_->{behaviour} eq 'nice' ? 'lollipop' : 'coal';
}
grep { $_->{age} < 16 } @neighbourhood;
say pp(@neighbourhood);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment