在其他語言中,我使用的就像Erlang和Python,如果我分割字符串而不關心其中一個字段,則可以使用下劃線佔位符。我在Perl試過這樣:使用虛擬佔位符的Perl分配
(_,$id) = split('=',$fields[1]);
,但我得到了以下錯誤:
Can't modify constant item in list assignment at ./generate_datasets.pl line 17, near ");"
Execution of ./generate_datasets.pl aborted due to compilation errors.
還包括Perl有,我可以改用創建一個無用的臨時變量的類似這樣的模式?
注意:即使在聲明中有效'my(undef,$ a,$ b)= ...' – ysth 2011-05-06 21:27:52
我想投票贊成,但使用'$ a'和'$ b'可以防止我。 – darch 2011-05-06 23:25:16
@darch:* eyeroll * – geekosaur 2011-05-06 23:27:23