How do I search a directory for all .XXX files and get a list of them in Perl?

假装没事ソ 提交于 2019-12-25 01:39:12

问题


I need to search in a directory for all the files that end in .123.

How do I (using Perl) get a list of those files?


回答1:


Simply:

@files = glob "$dirname/*.123";



回答2:


One way is to use glob:

use warnings;
use strict;

my @files = grep { -f } glob '*.123';



回答3:


glob should do the job.
If you want to search recursively, you can use File::Find.



来源:https://stackoverflow.com/questions/5300825/how-do-i-search-a-directory-for-all-xxx-files-and-get-a-list-of-them-in-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!