Last active
August 29, 2015 13:56
-
-
Save note103/8909409 to your computer and use it in GitHub Desktop.
Perl入学式2013年度第5回補講in東京よりmap, grep練習問題の校長の回答
This file contains hidden or 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/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; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果は以下。
\ [ [0] "papix.pl.bak", [1] "moznion.pm.bak", [2] "macopy.py.bak", [3] "boolfool.vim.bak" ] \ [ [0] "papix.pl", [1] "moznion.pm" ]