如何打印在Perl多维数组的一个阵列? [英] How to print one array of a multidimensional array in Perl?

查看:169
本文介绍了如何打印在Perl多维数组的一个阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!usr/bin/perl
@array = ();
open(myfile,"sometext.txt");
while(<myfile>)
{
    chomp;
    push(@array,[split(" ")]);
}
close(myfile);
print @array[0];

相反打印第一阵列的元件在此多维数组的,它输出的十六进制(?)指针参考。如果有人知道我怎么可以打印这个数组,请发表如何,这将大大AP preciated。

Instead of printing the elements of the first array in this multidimensional array, it outputs the hexadecimal(?) pointer reference. If anyone knows how I can print this array, please post how and it will be greatly appreciated.

推荐答案

在这里你去。

Perl的多维数组是真正的数组引用数组。 Perl中的引用只是一个标量。所以,当你想打印整个数组它打印出这一点参考。您需要使用@ {}标量的情况下更改为阵。

Perl's multi-dimensional arrays are really arrays of references to the arrays. In perl a reference is just a scalar variable. So, when you are trying to print your whole array it prints out just that reference. You need to use the @{} to change the context of the scalar to array.

#!/usr/bin/perl
@array = ();
open(myfile,"sometext.txt");
while(<myfile>)
{
    chomp;
    push(@array,[split(" ")]);
}
close(myfile);
print @{@array[0]};

这篇关于如何打印在Perl多维数组的一个阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆