Skip to content

Instantly share code, notes, and snippets.

@elee
Created April 26, 2010 04:49
Show Gist options
  • Save elee/378981 to your computer and use it in GitHub Desktop.
Save elee/378981 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
# output:
# foo
# bar
combine({
name => "foo",
surname => "bar"
});
# create sub with defaults
my $f = partial({
name => "larry",
surname => "wall"});
# output:
# paul
# wall
$f->({
name => "paul"});
# output:
# larry
# wall
$f->();
sub combine {
my ($args) = @_;
print "$args->{name}\n";
print "$args->{surname}\n";
}
sub partial {
my ($defaults) = @_;
return sub {
my ($args) = shift || {};
combine({%$defaults, %$args});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment