()
在 Perl 中使用与 example 有什么区别[]
?当它使用方括号时如何找到数组的大小?
my @myarr = ( # Parenthesis
[ "itemone", "itemoneb", "itemonec" ],
[ "itemtwo", "itemtwob", "itemtwoc" ]
);
my @myarr = [ # Square bracket
[ "itemone", "itemoneb", "itemonec" ],
[ "itemtwo", "itemtwob", "itemtwoc" ]
];
谢谢你的解释。我仍在努力理解这一点,目前这让我有点困惑。我仍然无法弄清楚如何在这里遍历我的数据:
#!/usr/bin/perl -w
use strict;
use FindBin qw($Bin);
use Cwd;
use Data::Dumper;
my @mynames = (
[ "myname", "mydescription", "mydata"],
[ "myname2", "mydescription2", "mydata2"],
[ "myname3", "mydescription3", "mydata3"],
);
go();
sub go {
start(\@mynames);
}
sub start {
my @input_name = shift;
# This works
#print @input_name->[0][0][0];
#die;
# This Shows
#print Dumper(@input_name);
#$VAR1 = [
# [
# 'myname',
# 'mydescription',
# 'mydata'
# ],
# [
# 'myname2',
# 'mydescription2',
# 'mydata2'
# ],
# [
# 'myname3',
# 'mydescription3',
# 'mydata3'
# ]
# ];
# How do I iterate?
#for my $i (0..@$input_name) {
# my $name = "";
# my $description = "";
# my $data = "";
#
#}
}