【发布时间】:2018-02-09 22:54:08
【问题描述】:
如果我在 perl 中查找文件名模式,您可以这样做:
ls -l | perl -n -e'if(/.*180205.*/){ print "$_\n"; }'
-n
导致 Perl 在您的程序周围假设以下循环,这使得它迭代文件名参数,有点像sed -n或awk:LINE: while (<>) { ... # your program goes here }
如何在 python3 中编写代码? (python3 --help 显示不是这样的选项)
【问题讨论】:
-
你是在命令行上设置还是 python 代码会这样做?
-
你可以通过
perl -n -E 'say if /180205/大大缩短 Perl 程序 -
对于熟悉 Python 但不熟悉 Perl 的任何人,您可能想描述一下
-n的确切作用。 -
其实
perl --help说-n的意思是假设“while () { ... }” 循环程序 -
既然可以
ls -l *180205*,为什么还需要perl或python?
标签: python python-3.x perl