- 论坛徽章:
- 12
|
本帖最后由 523066680 于 2017-12-29 19:54 编辑
回复 1# pony2001mx
感觉你写的很绕。以及,默认情况下不能将引用作为哈希的键。
参考 《Programming Perl》 关于引用的章节
References Don’t Work As Hash Keys
Hash keys are stored internally as strings. If you try to store a reference as a key in a hash, the key value will be converted into a string - $ perl -e '%h=map { @b=split; $x=[@b[0,1,2]]; ( $i++, $x ) } <>; for $y (values %h) { print "@{$y}\n" }' test.txt
复制代码
OR
- $ perl -ne 'print join q/ /, (split q/ /, $_)[0,1,2], qq/\n/' a.txt
复制代码
如果一定要将引用作为key,可以试试 Tie::RefHash 模块
|
|