perl的引用

标量引用  \$ $$
数组引用 \@ @$
hash引用 \% %$
子例程引用 \& &$

\$ \@ \% \& 会返回相应对象类型的一个标量引用
$$ @$ %$ &$会返回对象本身

匿名hash和命名hash的引用和解引用

[root@rwsoda203db1 perl_tidb]# cat p.pl
#!/usr/bin/perl
use strict "subs";
use strict;
use v5.16;
use warnings;
my $hash_ref = {'a'=>'A','b'=>'B'};
my %hash_a = ('c'=>'C','d'=>'D');
my $hash_a_ref = \%hash_a;
print "$hash_ref->{'b'}\n";
print "$hash_a{'c'}\n";
print "$hash_a_ref->{d}\n";
print "\$\$hash_a_ref{d}:$$hash_a_ref{d}\n";

my %hash_a_copy = %$hash_a_ref;
print "$hash_a_copy{c}\n";
print "\$\$hash_ref{a}:$$hash_ref{a}\n";

#标量引用

my $var_a = "zhongguo";
my $var_a_ref = \$var_a;

print "\$\$var_a_ref:$$var_a_ref\n";
[root@rwsoda203db1 perl_tidb]# ./p.pl
B
C
D
$$hash_a_ref{d}:D
C
$$hash_ref{a}:A
$$var_a_ref:zhongguo
[root@rwsoda203db1 perl_tidb]#

你可能感兴趣的:(perl)