如何读回Data :: Dumper的输出? [英] How do I read back in the output of Data::Dumper?
问题描述
假设我有一个使用 Data::Dumper
创建的文本文件,的行:
Let's say I have a text file created using Data::Dumper
, along the lines of:
my $x = [ { foo => 'bar', asdf => undef }, 0, -4, [ [] ] ];
我想重新读回该文件并重新获得$x
.我试过了:
I'd like to read that file back in and get $x
back. I tried this:
my $vars;
{
undef $/;
$vars = <FILE>;
}
eval $vars;
但是它似乎不起作用-$x
不仅没有定义,当我尝试使用它时,我得到警告,提示
But it didn't seem to work -- $x
not only isn't defined, when I try to use it I get a warning that
全局符号$ x需要明确的软件包名称.
Global symbol $x requires explicit package name.
什么是正确的方法? (是的,我知道这很丑陋.这是一个快速的实用程序脚本,而不是例如生命支持系统.)
What's the right way to do this? (And yes, I know it's ugly. It's a quick utility script, not e.g., a life-support system.)
推荐答案
以下是提供了两个不同选项的线程: 取消转储
Here's a thread that provides a couple different options: Undumper
如果您只是在寻找数据持久性,那么Storable模块可能是您的最佳选择.
If you're just looking for data persistence the Storable module might be your best bet.
这篇关于如何读回Data :: Dumper的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!