Skip to content

Instantly share code, notes, and snippets.

@rsimoes
Forked from gatlin/mymap.pl
Created December 27, 2011 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsimoes/1522531 to your computer and use it in GitHub Desktop.
Save rsimoes/1522531 to your computer and use it in GitHub Desktop.
Functional definition of map in Perl
#!/usr/bin/env perl
use strict;
use warnings;
sub myMap(&@) {
!wantarray && @_ - 1 || @_ > 1 && (
do {
local $_ = $_[1];
$_[0]->();
}, &myMap( $_[0], @_[2..$#_] )
);
}
print myMap { "$_\n" } 1..4;
print scalar( myMap { "$_\n" } 1..4 ), "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment