Created
April 26, 2010 04:49
-
-
Save elee/378981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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