与 -e 和 perl 中的正则表达式匹配的文件名 [英] File name matching with -e and regular expressions in perl

查看:76
本文介绍了与 -e 和 perl 中的正则表达式匹配的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查目录中是否存在文件.文件名的格式如下:

I need to check for the existence of a file in a directory. The file name has a pattern like:

/d1/d2/d3/abcd_12345_67890.dat

在我的程序中,我会知道文件名到abcd_

In my program, I will know the file name up to abcd_

我需要使用 -e 选项编写一个 if 条件并找到与上述给定模式匹配的文件.

I need to write an if condition using -e option and find the files matching above given pattern.

推荐答案

您可以使用 glob 返回名称与模式匹配的现有文件列表:

You can use glob to return a list of existing files whose name matches a pattern:

my @files = glob '/d1/d2/d3/abcd_*.dat';

在这种情况下,不需要执行 -e 文件测试.

In this case, there is no need to perform the -e filetest.

这篇关于与 -e 和 perl 中的正则表达式匹配的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆