我应该如何在Perl中序列化代码引用? [英] How should I serialize code references in Perl?

查看:177
本文介绍了我应该如何在Perl中序列化代码引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 nstore 一个也包含代码引用的Perl哈希。遵循此 perldoc 我写了这样的内容:

I wish to nstore a Perl hash which also contains a code reference. Following this perldoc I wrote something like this:

use strict;
use warnings;
local $Storable::Deparse = 1; 
my %hash = (... CODE => ...);
nstore (\%hash, $file);

我收到警告说名称Storable :: Deparse只能使用一次:在test4.pl第15行可能出现错字。。我想我可以明确地禁止这个警告,但它让我怀疑我是否做错了什么。

I get a warning saying Name "Storable::Deparse" used only once: possible typo at test4.pl line 15.. I guess I could specifically suppress this warning, but it makes me wonder if I'm doing anything wrong.

注意这个问题涉及到这个one 。不同的标题区分这两者将是最受欢迎的。

Note this question relates to this one. Different titles to distinguish between the two will be most welcomed.

推荐答案

在设置其中一个之前,您已经忽略加载Storable模块它的配置值。

You have neglected to load the Storable module, before setting one of its config values.

use strict;
use warnings;
use Storable qw(nstore);
local $Storable::Deparse = 1; 
my %hash = (... CODE => ...);
nstore (\%hash, $file);

这篇关于我应该如何在Perl中序列化代码引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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