Skip to content

Instantly share code, notes, and snippets.

@note103
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save note103/8909409 to your computer and use it in GitHub Desktop.

Select an option

Save note103/8909409 to your computer and use it in GitHub Desktop.
Perl入学式2013年度第5回補講in東京よりmap, grep練習問題の校長の回答
#!/usr/bin/env perl
use strict;
use warnings;
use DDP;
my @files = qw/papix.pl moznion.pm macopy.py boolfool.vim/;
sub map_bak {
my $array_ref = shift;
return [ map {$_ . '.bak'} @{$array_ref} ];
}
my $map_bak = map_bak(\@files);
p $map_bak;
sub grep_pl_and_pm {
my $array_ref = shift;
return [ grep { /\.p[lm]$/} @{$array_ref} ] ;
}
my $grep_pl_and_pm = grep_pl_and_pm (\@files);
p $grep_pl_and_pm;
@note103
Copy link
Author

note103 commented Feb 10, 2014

実行結果は以下。

\ [
    [0] "papix.pl.bak",
    [1] "moznion.pm.bak",
    [2] "macopy.py.bak",
    [3] "boolfool.vim.bak"
]
\ [
    [0] "papix.pl",
    [1] "moznion.pm"
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment