如何将perl哈希字符串引用转换为perl哈希引用 [英] how to convert the perl hash string reference to perl hash reference

查看:317
本文介绍了如何将perl哈希字符串引用转换为perl哈希引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 HASH(0x991f0dc)

因此,如果我们将上面的哈希引用存储为标量变量中的字符串, 在Perl程序中用%"取消引用它会引发错误,

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

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

以上是从Perl程序(我的请求解决方案)抛出的,将哈希字符串引用转换回Perl哈希引用.

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

推荐答案

您不能将其转换回.

HASH(0x991f0dc)不是哈希引用.它是变量的字符串表示形式,其中包含对该地址的哈希的引用.当您取消引用时所描述的错误消息表明您具有与此类似的内容:

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.

似乎是通过一个通过GEN0文件句柄读取的套接字获得的.谁向您发送数据结构的信息,那都是错的.

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.

他们需要对数据进行序列化,然后您需要对数据进行反序列化.做到这一点的好方法是 JSON .但是您也可以使用可存储,或

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.

这篇关于如何将perl哈希字符串引用转换为perl哈希引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆