为什么我的 Perl 单行报告“Bareword found where operator expected"? [英] Why does my Perl one-liner report "Bareword found where operator expected"?

查看:119
本文介绍了为什么我的 Perl 单行报告“Bareword found where operator expected"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to convert block size into MB. I am using the /e option in my substitution. When I add starting MB in substitution part it giving me the error.

例如:

这有效.

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

这给了我错误.

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.

任何帮助修复第二个?

推荐答案

/e 开关将替换表达式转换为正则 perl 表达式.您需要引用 ' MB' 并使用连接 (.) .

The /e switch turns the replace expression into a regular perl expression. You need to quote the ' MB' and use concatenation (.) .

's#(\d+)(\s+SELECT)#$1/(1024*1024*2) . q[ MB] . $2#e

应该可以.

这篇关于为什么我的 Perl 单行报告“Bareword found where operator expected"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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