【发布时间】:2020-09-24 03:58:03
【问题描述】:
我在 Perl 中有以下单行代码:
perl -MLingua::EN::Sentence=get_sentences -ne 'print "$_\n" for grep { /replace_me/i } @{get_sentences($_)}' "${filePath}"
我如何重新构建它,以便能够将“replace_me”部分替换为可以作为参数传递到脚本中的任何文本字符串(也称为变量)?
我了解您不能在单引号内添加变量,但我目前不确定如何使用双引号重新构造它。任何帮助将不胜感激。
【问题讨论】:
-
使用
-s选项传递变量perl,例如perl -sE 'say $foo' -- -foo=Foo