#!usr/bin/perl @array = (); open(myfile,"sometext.txt"); while(<myfile>) { chomp; push(@array,[split(" ")]); } close(myfile); print @array[0];
它不是在这个多维数组中打印第一个数组的元素,而是输出十六进制(?)指针引用.如果有人知道我如何打印这个数组,请发布如何,将非常感谢.
解决方法
干得好.
Perl的多维数组实际上是对数组的引用数组.在perl中,引用只是一个标量变量.因此,当您尝试打印整个数组时,它会打印出该引用.您需要使用@ {}将标量的上下文更改为数组.
#!/usr/bin/perl @array = (); open(myfile,[split(" ")]); } close(myfile); print @{@array[0]};