請注意以下幾個最基本的工作例如:IPC ::共享的變量,「不能用string ......作爲標REF ..」和內存地址
use warnings;
use strict;
use IPC::Shareable;
use Data::Printer;
IPC::Shareable->clean_up;
my $sharevar1 = "a";
my $sharevar2;
print "A: $sharevar1 $sharevar2\n";
p($sharevar1);
p($sharevar2);
my $glue1 = 'glu1';
my $glue2 = 'glu2';
my %options = (
create => 1, #'yes',
exclusive => 0,
mode => 0644, #0644,
destroy => 1, # 'yes',
);
my $sharevar_handle1 = tie $sharevar1, 'IPC::Shareable', $glue1 , \%options ; #
print "B1: $sharevar1 $sharevar2 - $sharevar_handle1\n";
my $sharevar_handle2 = tie $sharevar2, 'IPC::Shareable', $glue2 , \%options ; #
print "B2: $sharevar1 $sharevar2 - $sharevar_handle2\n";
p($sharevar1);
p($sharevar2);
$sharevar1 = "b";
#~ $sharevar1 = "AOE" . \$sharevar2;
$sharevar2 = 20;
print "C: ";
print "- $sharevar1 $sharevar2\n";
p($sharevar1);
p($sharevar2);
當我跑,我得到像下面的輸出 - 這是預期:
Use of uninitialized value $sharevar2 in concatenation (.) or string at tt.pl line 13.
A: a
"a"
undef
Use of uninitialized value $sharevar1 in concatenation (.) or string at tt.pl line 30.
Use of uninitialized value $sharevar2 in concatenation (.) or string at tt.pl line 30.
B1: - IPC::Shareable=HASH(0xa1dc1b8)
Use of uninitialized value $sharevar1 in concatenation (.) or string at tt.pl line 34.
Use of uninitialized value $sharevar2 in concatenation (.) or string at tt.pl line 34.
B2: - IPC::Shareable=HASH(0xa215b10)
undef (tied to IPC::Shareable)
undef (tied to IPC::Shareable)
C: - b 20
"b" (tied to IPC::Shareable)
20 (tied to IPC::Shareable)
但是,如果現在我試圖取消對「$sharevar1 = "AOE" . \$sharevar2;
」行,而註釋掉「$sharevar1 = "b";
「之上;那麼輸出我得到的是幾乎相同,只是在最後:
...
B2: - IPC::Shareable=HASH(0x852fb20)
undef (tied to IPC::Shareable)
undef (tied to IPC::Shareable)
Can't use string ("AOESCALAR(0x836bf88)") as a SCALAR ref while "strict refs" in use at /usr/local/share/perl/5.10.1/IPC/Shareable.pm line 741.
C: $
現在,事情是,這個「不能用string ......」實際上會導致系統崩潰......顯然,如果tie
d變量曾經通過\
獲得了一個引用,它獲得了一個值,如SCALAR(0x836bf88)
作爲字符串,這顯然被Perl解釋爲意味着一個地址...?!
而且我還以爲是Perl會在這種情況下匹配字符串的開始部分(SCALAR(...
) - 所以我想在前面加上字符串「AOE」騙 - 但奇怪的是,Perl的仍然注意到(彷彿它是尋找一些正則表達式「0X withing括號」還挺符合):「不能用字符串(」 AOESCALAR(0x836bf88)「)作爲標參考」 ......
我的問題是 - 我推理Perl和IPC :: Shareable如何解釋地址(否則存儲爲「字符串」)正確(否,請參閱下面的編輯;是的,參見post);並且不管是否如此,我將如何將地址存儲到IPC :: Shareable中?
非常感謝任何答案,
乾杯!
編輯:嗯,很明顯,通常都與作品中包含字符串不會忽略打印字符串變量確定 - 所以這個問題是IPC ::共享的具體,我想:
DB<1> $ttt = "aa"
DB<2> p $ttt
aa
DB<3> $eee = \$ttt
DB<4> p $eee
SCALAR(0xa382668)
DB<5> $eee = "erw".\$ttt
DB<6> p $eee
erwSCALAR(0xa382668)
DB<7> q
@Borodin您好,感謝您的回答!我嘗試過更新,'perl'說:'IPC ::共享的是最新的(0.6).'我已經更新[我的文章](http://stackoverflow.com/a/10668741/277826);我可以證實,只要資本「'SCALAR'」不存在,就可以打印變量(即使是小寫的「scalar」)。我也希望「_recognized as not an reference_」,但顯然不是這樣,至少在我的Ubuntu盒子上。非常感謝 - 歡呼! – sdaau