in reply to Re: Extracting a hash reference from a string
in thread Extracting a hash reference from a string

This is exactly the pointer (pun intended :) I was looking for.

The following code accomplishes my task:

#!/usr/bin/perl -T use strict; use warnings; use Devel::Pointer; eval { require('some_code.pl'); }; if ($@) { my $start = index($@, 'HASH(0x') + 7; my $end = index($@, ')', $start); my $hex = substr($@, $start, $end-$start); my $addr = hex($hex); my $href = unsmash_hv(0+$addr); print("$$href{'Error data'}\n"); } # EOF

Since the hash is guaranteed (in my case) to have a non-zero reference count, this code is safe for my purposes.

Replies are listed 'Best First'.
Re: Re: Re: Extracting a hash reference from a string
by bart (Canon) on Mar 23, 2003 at 09:07 UTC
    my $start = index($@, 'HASH(0x') + 7; my $end = index($@, ')', $start); my $hex = substr($@, $start, $end-$start);
    Why the handwork? Why aren't you using a regex?
    my($hex) = $@ =~ /HASH\(0x(\w+)\)/;