+ -
当前位置:首页 → 问答吧 → 为何map返回的不是相匹配的原内容,而是pattern本身?

为何map返回的不是相匹配的原内容,而是pattern本身?

时间:2011-03-30

来源:互联网

如题,请教各位。新手,不好意思,测试了很久,太耽误时间了。
代码如下:
思路:输入一个要查询的字符串,检查某个目录下所有文件名是否有匹配的。如果有,则返回所有匹配的文件名。

use 5.010;
use Cwd;
chomp( $mydir = cwd);
#@myfiles = glob "$mydir/xiaoyangtuo/*";
@myfiles = glob "$mydir/xiaoyangtuo/*";
#print "\@myfiles are: @myfiles\n";
print "input a pattern as part of file name for earhing: \n";
chomp ($mypattern =<STDIN>);
while ($mypattern) {
       @myfile_search = map /$mypattern/g, @myfiles;
       #@myfile_search = map /$mypattern/g, glob(".* *"); #this line should go with chdir which is not correct right now;
        print "myfile_search is: @myfile_search \n";
        chomp ($mypattern =<STDIN>);
}

作者: perlplus33   发布时间: 2011-03-30

改 map 为 grep 结果就是我所要得内容。

但是用map 如何做呢?学习中,希望能有人在我花费大量时间之前,给我指点一下,谢谢。

作者: perlplus33   发布时间: 2011-03-30

热门下载

更多