Perl hash Data :: Dumper [英] Perl hash Data::Dumper

查看:127
本文介绍了Perl hash Data :: Dumper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Perl中,我需要分析一个巨大的散列,因此我使用 数据将其打印到文件中:: Dumper 模块。因为它是一个巨大的文件,所以很难阅读。是否有可能以某种方式打印 Dumper 输出很好,所以当我找到一个我正在寻找的字符串时,我将能够立即看到关键结构,我所在的字符串寻找存储?



目前我只使用一个简单的代码:

 使用Data :: Dumper; 
...
print Dumper $ var;

获得不错输出的最佳语法或替代方法是什么?
<

  $ Data :: Dumper:

:缩进= 1;
$ Data :: Dumper :: Sortkeys = 1;

加上 Data :: Dumper 。当你的数据结构深入几层时,第一条语句使得输出更加紧凑并且可读性更高。第二条语句可以更容易地扫描输出并快速找到您最感兴趣的键。

如果数据结构包含二进制数据或嵌入的制表符/换行符,考虑

  $ Data :: Dumper :: Useqq = 1; 

这将为该数据输出合适的可读表示。



更多 perldoc


In Perl I need to analyze a huge hash, so I print it into a file using Data::Dumper module. Because it is a huge file, it is very hard to read. Is it possible somehow to print Dumper output nicely, so when I will find a string that I am looking for, I will be able to see immediately key structure where the string I am looking for is stored?

Currently I am using just a simple code:

            use Data::Dumper;
            ...
            print Dumper $var;

What is the best syntax or alternative to get nice output?

解决方案

I almost always set

$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;

with Data::Dumper. The first statement makes the output more compact and much more readable when your data structure is several levels deep. The second statement makes it easier to scan the output and quickly find the keys you are most interested in.

If the data structure contains binary data or embedded tabs/newlines, also consider

$Data::Dumper::Useqq = 1;

which will output a suitable readable representation for that data.

Much more in the perldoc.

这篇关于Perl hash Data :: Dumper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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