2011-09-25 39 views
2

正如標題所示,我該如何實現這一目標?Perl語法錯誤:在操作員期望的地方發現了Bareword

我一直在下面的教程,但我得到一個語法錯誤:

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

使用嚴格;使用警告;在你的程序的頂部將有助於抓住這個東西。 –

回答

5

2names是無效的變量名。名稱不能以數字—開頭,他們必須以字母或下劃線開頭。

+0

啊!我明白了,代碼對我來說看起來很好:D,知道這很簡單:P謝謝 –

+0

@Ben:很高興幫助。如果我將帖子的標題更改爲「Perl語法錯誤:在操作員預期的位置找到了Bareword」,那麼您會介意嗎?因此,對於將來有同樣問題的人員,它更容易搜索到? –

+0

當然,我會做,謝謝 –

相關問題