gpt4 book ai didi

perl - Perl $$(双美元)符号-它取消引用什么?

转载 作者:行者123 更新时间:2023-12-04 22:40:06 24 4
gpt4 key购买 nike

我看到了关于Perl $$var -- two dollar signs as a sigil?的问题,该双美元符号用于取消引用

我有这个Perl代码

sub sock_initialize {

my $sock = q{};
my $port = q{};

# $name running
my $max_count = 250;
my $timeout = 5;
my $max_retries = 36;

# Get a port for our server.
$sock = IO::Socket::INET->new(
Listen => SOMAXCONN, # listen queue depth
LocalPort => 0,
Reuse => 1
);

die "Unable to bind a port: $!" if !$sock;

$port = $sock->sockport();
my $ip = inet_ntoa( scalar gethostbyname( $HOST ));
my $uid = (getpwuid( $> ))[2];
my $queue = join(":", $ip, $port, $$, $uid);

print sprintf("started on port $port ($$), SOMAXCONN=%d\n", SOMAXCONN);

return $sock;
} ## end sub sock_initialize

从上面的代码中,双美元符号解引用了什么? my $queue = join(":", $ip, $port, $$, $uid);

最佳答案

简单地

和其他POSIX下的一样: $$是当前进程ID(PID)

对于man perlvar:

  $PROCESS_ID
$PID
$$ The process number of the Perl running this script. Though you can
set this variable, doing so is generally discouraged, although it can
be invaluable for some testing purposes. It will be reset
automatically across "fork()" calls.


注意:来自 man perl
Reference Manual
perlsyn Perl syntax
perldata Perl data structures
...
perldebug Perl debugging
perlvar Perl predefined variables
...


并从 man POSIX ...

   "getpid"
Returns the process identifier. Identical to Perl's builtin
variable $$, see "$PID" in perlvar.

关于perl - Perl $$(双美元)符号-它取消引用什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48760722/

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