in reply to Change a SCALAR into a HASH using just Perl without any XS code?

I don't see where you specify what value you want the hash to have.

Alternatively, see Object::Destroyer

  • Comment on Re: Change a SCALAR into a HASH using just Perl without any XS code?

Replies are listed 'Best First'.
Re^2: Change a SCALAR into a HASH using just Perl without any XS code?
by tod222 (Pilgrim) on Nov 01, 2010 at 05:32 UTC

    You're right, I didn't specify a value for the hash, because it doesn't contain anything -- it's XS code acting like a hash, or in the problematic case, XS code acting like a scalar.

    I tried the following which appeared to work in a trivial test case, but it corrupted memory causing a Segfault in another location when I tested it in real code:

    my $aref = $f->getVariants(); # reference to array containing many Foo my $sfoo = shift(@$aref); my $tiefoo = {}; # warning - this causes segfaults bless $tiefoo, 'Bar::Foo'; tie %{$tiefoo}, 'Bar::Foo', $sfoo; $tiefoo->ACQUIRE();

    So my conclusion is that it's not possible to fix this in pure Perl. The C++ or SWIG wrapper code must be modified.

      because it doesn't contain anything

      Creating an empty hash is very easy...

      There's obviously some information the module requires from this hash. You can't create a hash that meets the module's needs until you figure out what this information is. This is what you need to do first.