Perl 语法错误:在应该有运算符的位置找到了裸字。

3

如标题所示,我该如何实现这个功能?

我一直在跟随教程操作,但是我收到了语法错误的消息:

Bareword found where operator expected at arrays_and_variables.pl line
26, near "$2names"
        (Missing operator before names?) syntax error at
arrays_and_variables.pl line 26, near "$2names " Execution of
arrays_and_variables.pl aborted due to compilation errors.

我目前的代码如下:

```

@names = ('james','dylan','max');

# join elements of array into a schalar variable.
$2names = join ('', @names);
print $s2names;

2
在你的程序顶部加上"use strict;"和"use warnings;"可以帮助捕获这些问题。 - Bill Ruppert
1个回答

5

2names是一个无效的变量名。 变量名不能以数字开头,必须以字母或下划线开头。


啊!我明白了,代码看起来很好:D,知道这是一些简单的东西:P谢谢。 - Ben Thorsby
@Ben:很高兴能帮忙。你介意我将你的帖子标题改为类似于“Perl语法错误:在预期运算符位置找到裸字”,这样以后遇到相同问题的人更容易搜索到吗? - Samir Talwar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接