你为什么要分配给$$?

Cha*_*ens 12 perl

perldoc perl5150delta 说:

   $$ can be assigned to
       $$ was made read?only in Perl 5.8.0.  But only sometimes: "local $$"
       would make it writable again.  Some CPAN modules were using "local $$"
       or XS code to bypass the read?only check, so there is no reason to keep
       $$ read?only.  (This change also allowed a bug to be fixed while
       maintaining backward compatibility.)
Run Code Online (Sandbox Code Playgroud)

$$ 是当前的进程ID,为什么你会分配给它?

bri*_*foy 8

在CPAN中只有几个(字面上)人们想要分配的地方$$,而且主要用于测试(我还没有理解IPC::Messaging).我不喜欢这个功能,特别是因为有更好的方法来获得相同的效果.Perl 5 Porters添加了这个功能,因为他们可以而且他们宁愿不让两个案例做得更好.如果您阅读p5p线程,很明显此功能不是由需要驱动的.

我在隐藏界面背后的低级细节中了这篇文章.

但是,我可能错了,因为我对低级黑魔法并不擅长.我知道有必要协调PID,但到目前为止,我认为这$$不是唯一的方法.如果有人有可以向我解释的用例,我会更新该帖子.