Skip to content

Instantly share code, notes, and snippets.

@yanick
Created November 8, 2012 20:30
Show Gist options
  • Save yanick/4041382 to your computer and use it in GitHub Desktop.
Save yanick/4041382 to your computer and use it in GitHub Desktop.
hash_map
#!/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