简体   繁体   English

如何将perl哈希字符串引用转换为perl哈希引用

[英]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, 所以上面的哈希引用在标量变量中存储为字符串,如果我们在Perl程序中用“%”取消引用它会引发错误,

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. 以上是从Perl程序抛出的,我请求解决方案,将哈希字符串引用转换回Perl哈希引用。

You can't convert this back . 你无法将其转换回来

The HASH(0x991f0dc) is not a hash reference. HASH(0x991f0dc)不是哈希引用。 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: 你在deref它时描述的错误信息表明你有类似的东西:

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. 看起来你通过GEN0文件句柄读取了一个套接字。 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 . 这样做的好方法是JSON But you could also use Storable , or Sereal . 但你也可以使用StorableSereal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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