【发布时间】:2023-04-09 21:43:01
【问题描述】:
我正在寻找一个 Perl oneliner(将其插入到 Bash 脚本中),我需要下一个接口:
perl -0777 -nlE 'commands' file1 file2 .... fileN
我创建了下一个:
perl -0777 -lnE 'BEGIN{$str=quotemeta(do{local(@ARGV, $/)="file1"; <>})} say "working on $ARGV" if $_ =~ /./' "$@"
更漂亮:
perl -0777 -lnE '
BEGIN{
$str = quotemeta(
do{
local(@ARGV, $/)="file1"; <> #localize ARGV to "file1.txt" for <>
}
)
}
say "working on $ARGV" if $_ =~ /./ #demo only action
' "$@"
它可以工作,但是每次需要更改file1时,我都需要编辑源代码。
如何将脚本更改为以下内容?
- 将
$ARGV[0](file1)插入$str(在BEGIN块中) - 然后在主循环中将其他参数添加到
$_中
【问题讨论】:
标签: perl