in reply to [SOLVED] Printing an object when you only have the refaddr string for it

The number is the address[1] of the SV[2], so it's just a question of casting the number into a pointer. To work with it from Perl, you'd need a reference (since it's not necessarily a scalar), so you'd pass the pointer to newRV_inc.
use Test::More tests => 2; use Inline C => <<'__EOC__'; SV* addr_to_ref(IV addr) { return newRV_inc((SV*)addr); } __EOC__ { my @a = qw( a b c ); my $ref = \@a; my $stringified_ref = "$ref"; my $addr = $stringified_ref =~ /0x([0-9a-f]+)/ ? hex($1) : die; my $ref2 = addr_to_ref($addr); is(0+$ref, 0+$ref2); is("@$ref", "@$ref2"); }

That's assuming the SV is still allocated, of course.


  1. Numerical representation of a pointer.
  2. Or AV, HV, etc. For the purposes of this post, I consider these to be subtypes of SV.

Replies are listed 'Best First'.
Re^2: Printing an object when you only have the refaddr string for it
by delias_ (Acolyte) on Nov 05, 2015 at 21:23 UTC
    Yeah, I verified it's still allocated using Data::TreeDumper. Will give this a run through and let you know what happens.

    LOOKING FOR ADDR ARRAY(0x7fa9bc68be78) . . . | | | | | | | | | | | | | | | |- 3 [ +A220] ARRAY(0x7fa9bc68be78)

    Nested quite deep as you can see.
      Yeah this definitely does what I was wanting. Now to go read up on some perlguts, thanks :)
      LOOKING FOR ADDR: ARRAY(0x7faf34532148) PRINTING REF: $VAR1 = [ 'curItem', 0 ]; . . . | | | | | | | | | | | | | | | |- 3 [ +A220] <187> ARRAY(0x7faf34532148)
      The hex conversion throws a portable warning (to warn 32 bit users I guess) if you weren't aware, but that's neither here nor there.