为什么我的Perl单行报告"Bareword发现了运营商的预期"?

sfg*_*ups 0 regex perl syntax-error string-formatting

我想将块大小转换为MB.我/e在替换中使用了该选项.当我在替换部分添加起始MB时,它给我错误.

例如:

这有效.

 echo "16777216 SELECT" |perl -lane 's#(\d+)(\s+SELECT)#$1/(1024*1024*2)#e; print'
8
Run Code Online (Sandbox Code Playgroud)

这给了我错误.

echo "16777216 SELECT" |perl -lane 's#(\d+)(\s+SELECT)#$1/(1024*1024*2) MB $2#e; print'
Bareword found where operator expected at -e line 1, near ") MB"
        (Missing operator before MB?)
syntax error at -e line 1, near ") MB "
Execution of -e aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)

任何修复第二个的帮助?

cod*_*ict 6

更改

(1024*1024*2) MB $2
Run Code Online (Sandbox Code Playgroud)

(1024*1024*2)."MB".$2
Run Code Online (Sandbox Code Playgroud)

/e修饰符告诉引擎对待替换字段为Perl代码.