简体   繁体   中英

how to convert the perl hash string reference to perl hash reference

 HASH(0x991f0dc)

so the above hash reference is stored as string in scalar variable,if we dereference it with "%" in the Perl program it throws error,

Can't use string ("HASH(0x991f0dc) ") as a HASH ref while "strict refs" in use at tcpclient1.pl line 49, <GEN0> line 1

this above is throws from Perl program,i request solution,to convert back the hash string reference to Perl hash reference.

You can't convert this back .

The HASH(0x991f0dc) is not a hash reference. It is the string representation of a variable that contains a reference to a hash at that address. The error message you describe when you deref it points to that you have something similar to this:

my $foo = 'HASH(0x991f0dc)';
print %$foo;

Now that won't work, because the actual data structure is not there.

It looks like you got this over a socket that you read from through the GEN0 filehandle. Whoever sends you that data structure is doing something wrong.

They need to serialize the data, and then you need to deserialize it back. A good way to do that is JSON . But you could also use Storable , or Sereal .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM