"print $variable" gives me REF(0x8fdc2d4) instead of HASH(0x....)

  • Thread starter Sébastien Cottalorda
  • Start date
S

Sébastien Cottalorda

Hi all,

I'm trying to add Hash::Flatten functionality to the IPC::Shareable
module.

In IPC::Shareable, I've that function:
sub _freeze {
my $s = shift;
my $water = shift;
....
my $ice = freeze $water;
....
$s->shmwrite($ice);
}

I'm trying to add Hash::Flatten like this:
sub _freeze {
my $s = shift;
my $water = shift;
....
$water = flatten($water, { HashDelimiter => '->', ArrayDelimiter
=> '=>', });
my $ice = freeze $water;
....
$s->shmwrite($ice);
}

unfortunately, sometimes, i obtains:
"Not a SCALAR reference at /home/workspace/panneau/modules/IPC/
Shareable.pm line 717."
and the module crashes.
When I print $water just before flatten(...), I get REF(0x8fdc2d4)
instead of HASH(0x...)

With the Data::Dumper module, I obtains:
$water = \{
'key' => 'value',
'another_key => {
'key1' => 'value1',
....
},
}

How can I transform $water from REF(0x....) to HASH(0x....)

Thanks in advance for any kind of help.

Sebastien
 
S

smallpond

Hi all,

I'm trying to add Hash::Flatten functionality to the IPC::Shareable
module.

In IPC::Shareable, I've that function:
sub _freeze {
    my $s  = shift;
    my $water = shift;
...
    my $ice = freeze $water;
...
    $s->shmwrite($ice);

}

I'm trying to add Hash::Flatten like this:
sub _freeze {
    my $s  = shift;
    my $water = shift;
...
    $water = flatten($water, { HashDelimiter => '->', ArrayDelimiter
=> '=>', });
    my $ice = freeze $water;
...
    $s->shmwrite($ice);

}

unfortunately, sometimes, i obtains:
"Not a SCALAR reference at /home/workspace/panneau/modules/IPC/
Shareable.pm line 717."
and the module crashes.
When I print $water just before flatten(...), I get REF(0x8fdc2d4)
instead of HASH(0x...)

With the Data::Dumper module, I obtains:
$water = \{
    'key' => 'value',
    'another_key => {
        'key1' => 'value1',
        ....
    },

}

How can I transform $water from REF(0x....) to HASH(0x....)

Thanks in advance for any kind of help.

Sebastien

Is the ref to a ref to a hash? ie. $water = \\%h?
$rapids = ref $water eq "REF" ? %$water : $water;
 
S

Sébastien Cottalorda

Is the ref to a ref to a hash?  ie. $water = \\%h?
$rapids = ref $water eq "REF" ? %$water : $water;

Sorry, I obtain :
Not a HASH reference at /blah_blah../Shareable.pm line 681
It seems not to be only a ref to a ref to a hash.
I do not explain how Data::Dumper manage to dump it like this:
$VAR=\{ .... }
I try to look into the Dumper package but I lost me ....
 
P

Peter Makholm

I do not explain how Data::Dumper manage to dump it like this:
$VAR=\{ .... }

Because that in a correct syntax for making a reference to a
hash-reference. See 'perldoc perlref'.

The outer ref is made by Rule 1: "By using the backslash operator on a
variable, subroutine, or value.". Here it is used on a value, which
happens to be a reference (byt rule 3) itself.

So Data::Dumper dumps it correct.

//Makholm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top