2、数组引用
[root@trffic2 perl]# cat reference.pl
#!/usr/bin/perl
my @array =qw/John Paul May/;
my $array_ref = \@array;
#print @{$array_ref};
print "${$array_ref}[0]\n";
print "${$array_ref}[1]\n";
print "${$array_ref}[2]\n";
print "${$array_ref}[3]\n";
[root@trffic2 perl]# perl reference.pl
John
Paul
May
[root@trffic2 perl]#
[root@trffic2 perl]# cat reference4.pl
#!/usr/bin/perl
my @array= (1..10);
my $ref = \@array;
print "@$ref\n";
[root@trffic2 perl]# perl reference4.pl
1 2 3 4 5 6 7 8 9 10
[root@trffic2 perl]#
3、关联数组引用
[root@trffic2 perl]# cat reference2.pl
#!/usr/bin/perl
my %hash =qw/John 24 Paul 30 May 26/;
my $hash_ref = \%hash;
print "${$hash_ref}{John}\n";
print "${$hash_ref}{Paul}\n";
print "${$hash_ref}{May}\n";
[root@trffic2 perl]# perl reference2.pl
24
30
26
[root@trffic2 perl]# cat reference3.pl
#!/usr/bin/perl
my %hash =qw/John 24 Paul 30 May 26/;
my $hash_ref = \%hash;
for (keys %{$hash_ref}){
print ${$hash_ref}{$_}."\n";
}
[root@trffic2 perl]# perl reference3.pl
24
26
30
[root@trffic2 perl]#
阅读(621) | 评论(0) | 转发(0) |