是否可以将散列转换为perl中的数组,但不使用其他变量?这按预期工作,但使用了另一个变量(@arr):
perl -wlae '%hash=(name=>"linus", forename=>"torvalds "); @arr=%hash; print "@arr"'我已经尝试过了,但都不起作用(顺便说一句,它们是做什么的?):
perl -wlae '%hash=(name=>"linus", forename=>"torvalds "); print "@hash"'
perl -wlae '%hash=(name=>"linus", forename=>"torvalds "); print "%@hash"'
perl -wlae '%hash=(name=>"linus", forename=>"torvalds "); print "@%hash"'发布于 2013-01-13 20:49:38
perl -wlae '%hash=(name=>"linus", forename=>"torvalds "); print (%hash);'将表达式放在圆括号中会在列表上下文中计算它,就像赋值给列表变量一样。
在print的情况下,这种转换是不必要的,因为它对数组和散列都使用列表上下文。但是如果你想用散列做其他数组风格的事情,你可以这样做,例如
$first = (%hash)[0];
echo $first;https://stackoverflow.com/questions/14303389
复制相似问题