Skip to content

Instantly share code, notes, and snippets.

@andrewsolomon
Created May 21, 2017 21:50
Show Gist options
  • Save andrewsolomon/15c02823d91c568128928311cc0fa481 to your computer and use it in GitHub Desktop.
Save andrewsolomon/15c02823d91c568128928311cc0fa481 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dump 'pp';
use feature 'say';
sub greet_friend {
my %friend = (
age => 5,
reading => 'Encyclopedia Britannica',
@_
);
return unless $friend{name};
my $response = "Hi $friend{name}! I'm ".($friend{age}+1)." and I read $friend{reading} ages ago. Totally boring.";
delete $friend{age};
delete $friend{name};
delete $friend{reading};
return $response unless keys(%friend);
$response .= ' But I like ';
$response .= join(' and ', map { $friend{$_}.' as a '.$_ } keys (%friend)).'.';
return $response;
}
say greet_friend(
name => 'Dazza',
age => 61,
reading => 'Shake Milk',
hobby => 'Panda',);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment