gpt4 book ai didi

perl - perl 中的 $$ 实际返回什么?

转载 作者:行者123 更新时间:2023-12-02 06:16:38 24 4
gpt4 key购买 nike

我是 Perl 的新手,从头开始学习。我读过 $$返回

The pid of the Perl process running this script.



按照下面的链接,

http://www.tutorialspoint.com/perl/perl_special_variables.htm

我有以下正在 Windows 机器上执行的 Perl 脚本,
sub test
{
my ($surrogate_name) = @_;
if((defined $surrogate_name) && ($surrogate_name == 1))
{
print "Done!"."\n";
}
return $surrogate_name;
}

sub t
{
my ($surrogate_name) = @_;
my $record;
my $surrogate_value;
$record = &test($surrogate_name);
print $record."\n";
if ($record)
{
print "B"."\n";
$surrogate_value = $$record{$surrogate_name};
}
print $surrogate_value."\n";
print "A"."\n";
return $surrogate_value;
}

&t(1);

在这段代码中,我观察到除了 $surrogate_value 之外的所有内容都被打印出来了。 .

请澄清我是什么 $$实际上是什么意思以及为什么它没有在我的脚本中返回任何内容。

提前致谢...

最佳答案

$$返回当前运行脚本的进程 ID。

但在你的情况下 $surrogate_value = $$record{$surrogate_name}这是一个完全不同的概念,即取消引用。

例如 $$ 与变量名称一起使用以取消引用它。

my $a = 10; #declaring and initializing a variable.
my $b = \$a; #taking scalar value reference
print $$b; #now we are dereferencing it using $$ since it is scalar reference it will print 10

my %hashNew = ("1" => "USA", "2" => "INDIA"); #declaring a hash
my $ref = \%hashNew; #taking reference to hash
print $$ref{2}; #this will print INDIA we derefer to hash here

如需更多理解,请阅读 perl 中的引用和取消引用。

关于perl - perl 中的 $$ 实际返回什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28936160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com