Created
November 8, 2012 20:30
-
-
Save yanick/4041382 to your computer and use it in GitHub Desktop.
hash_map
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
#!/usr/bin/perl | |
use 5.10.0; | |
use strict; | |
use warnings; | |
sub hash_map(&+) { | |
my( $sub, $hash ) = @_; | |
my @mapped; | |
push @mapped, $sub->() | |
while ($a,$b) = each %$hash; | |
return @mapped; | |
} | |
my %my_hash = ( | |
a => 1, | |
b => 2, | |
c => 3, | |
); | |
say for hash_map { "$a : $b" } %my_hash; | |
say for hash_map { "$a : $b" } { z => 3 }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment