How do I read back in the output of Data::Dumper?

前端 未结 9 1584
暖寄归人
暖寄归人 2021-02-10 02:14

Let\'s say I have a text file created using Data::Dumper, along the lines of:

my $x = [ { foo => \'bar\', asdf => undef }, 0, -4, [ [] ] ];
9条回答
  •  温柔的废话
    2021-02-10 02:42

    As others have already said, you'd probably be better off storing the data in a better serialisation format:

    • Storable - this is quick and easy, but fairly Perl-specific (but will satisfy your need for a quick solution in a relatively unimportant script easily)
    • YAML, using the YAML module, or YAML::Tiny, or YAML::Any as a wrapper to take advantage of whatever JSON module(s) are available on your system
    • JSON, using the JSON module, or JSON::XS for more speed (or JSON::Any as a wrapper to take advantage of whatever JSON module(s) are available on your system)
    • XML, using the XML-Simple module, or one of the other XML modules.

    Personally, I think I'd aim for YAML or JSON... you can't get much easier than:

    my $data = YAML::Any::LoadFile($filename);

提交回复
热议问题