Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
反斜杠'\';用perl语言是什么意思?_Perl_Backslash - Fatal编程技术网

反斜杠'\';用perl语言是什么意思?

反斜杠'\';用perl语言是什么意思?,perl,backslash,Perl,Backslash,在上图中,perl变量前面有\个,反斜杠是什么意思?在本例中,反斜杠表示变量的引用 阅读了解更多信息在Perl中,您可以在标量变量中保存对另一个变量的引用: my $string = "Test"; my $str_ref = \$string; my @list = (1, 2, 3); my $lst_ref = \@list; my %hash = ('a' => 1, 'b' => 2); my $hsh_ref = \%hash; 要读取或修改引用的变量,必须取消引用


在上图中,perl变量前面有\个,反斜杠是什么意思?

在本例中,反斜杠表示变量的引用


阅读了解更多信息

在Perl中,您可以在标量变量中保存对另一个变量的引用:

my $string = "Test";
my $str_ref = \$string;

my @list = (1, 2, 3);
my $lst_ref = \@list;

my %hash = ('a' => 1, 'b' => 2);
my $hsh_ref = \%hash;
要读取或修改引用的变量,必须取消引用它。为此,请使用原始变量类型的有趣字符:

$$str_ref = "Something else";
print $string; # -> Something else
print $$str_ref; # -> The same

@$lst_ref = (4, 5, 6);
print join(' ', @list); # -> 4 5 6
print join(' ', @$lst_ref); # The same

%$hsh_ref = ('c' => 3, 'd' => 4);
print join(' ', sort values %hash); # -> 3 4
print join(' ', sort values %$hsh_ref); # The same
可以使用
->
运算符访问列表引用和哈希引用的引用值:

print $lst_ref->[0]; # -> 4

print $hsh_ref->{'c'}; # -> 3

解除引用的较长语法是使用
{}
${$str_ref}
{$lst_ref}
%{$hsh_ref}

将代码作为文本添加,而不是将immageCode作为文本添加。为什么很多人认为张贴代码图片很有用?请在提问之前做些调查。如果有,您会发现类似的问题:。(在我看来,你的问题应该被这个问题愚弄了——虽然我不能投票结束)是的,我知道,但是如何结束这个问题?@downvoter谢谢dir downvoting,没有解释