- 论坛徽章:
- 3
|
原帖由 _Erics 于 2008-12-9 23:41 发表 ![]()
刚开始看
在练习的时候遇到一个问题,两段语义相近的代码,一个能正常运行,一个报语法错误,
不知哪里出错了。
@array = qw(This is Hello World);
$blank = " ";
@result = map {$blank,$_,"\n"} @array ...
- @result = map {+" ",$_,"\n"} @array;
复制代码
perldoc -f map |less -p '"\{" starts'
"{" starts both hash references and blocks, so "map { ..." could be either the start of map BLOCK LIST or map EXPR, LIST. Because perl doesn't look ahead for the closing "}" it has to take a guess at which its dealing with based what it finds just after the "{". Usually it gets it right, but if it doesn't it won't realize something is wrong until it gets to the "}" and encounters the missing (or unexpected) comma. The syntax error will be reported close to the "}" but you'll need to change something near the "{" such as using a unary "+" to give perl some help: |
|