Please note the following minimal working example:
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);
When I run this, I get an output like below - which is as expected:
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)
However, if now I try to uncomment the "$sharevar1 = "AOE" . \$sharevar2;
" line, while commenting out the "$sharevar1 = "b";
" above it; then the output I get is mostly the same, except at the end:
...
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: $
Now, the thing is that this "Can't use string ..." actually causes a crash... Apparently if a tie
d variable ever gets assigned a reference via \
, it gets a value like SCALAR(0x836bf88)
as a string, which apparently gets interpreted by Perl afterwards to mean an address... ?!
And I thought that Perl would in that case match the starting part (SCALAR(...
) of the string - and so I tried to cheat by prepending string "AOE" - but the strange thing is, Perl still noticed (as if it is looking for some regex for "0x withing parenthesis" kinda match): "Can't use string ("AOESCALAR(0x836bf88)") as a SCALAR ref" ...
My question is - is my reasoning about how Perl and IPC::Shareable interpret an address (which is otherwise stored as a "string") correct (no, see edit below; yes, see post); and regardless if it is, how would I go about storing an address into an IPC::Shareable?
Many thanks in advance for any answers,
Cheers!
EDIT: Well, apparently, normally all works OK with printing string variables that contain string adresses - so this problem is IPC::Shareable specific, I guess:
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