【发布时间】:2019-02-12 09:30:07
【问题描述】:
为什么除法不起作用?
echo 'cb0' | perl -p -e 's/(\w{3})/sprintf("%d", ( hex($1)/4 ))/e'
Number found where operator expected at -e line 1, near
"s/(\w{3})/sprintf("%d", ( hex($1)/4" syntax error at -e line 1, near
"s/(\w{3})/sprintf("%d", ( hex($1)/4" Execution of -e aborted due to
compilation errors.
原始输入数据是 12 位十六进制数。
【问题讨论】:
-
除法中的
/被视为正则表达式的分隔符。为什么要在替换零件中进行划分?你的输入数据是什么?很可能,unpack是一个更好的选择。