Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Extracting a hash reference from a string

by kschwab (Priest)
on Mar 23, 2003 at 02:16 UTC ( #245231=note: print w/ replies, xml ) Need Help??

Comment on Re: Extracting a hash reference from a string
Re: Re: Extracting a hash reference from a string
by Anonymous Monk on Mar 23, 2003 at 03:49 UTC

    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.

      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+)\)/;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://245231]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (15)
As of 2014-09-17 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (79 votes), past polls