如何控制Data :: Dumper输出的格式?

问题描述:

我正在使用Data::Dumper::Dumper()方法.输出效果不错,但可以使其紧凑,美观.

I am using Data::Dumper::Dumper() method. The output is good, but can be made little compact and more good looking.

我如何控制它?有什么更好的选择?

How I can control it? What are the better alternatives?

看看数据:: Dump 用于类似于Data :: Dumper的东西,但是在漂亮的打印方面可以说更好.

Take a look at Data::Dump for something similar to Data::Dumper but arguably better at pretty printing.

编辑(20120304):我完全忘记了这个问题,但是今天这个问题被否决了,这使我记忆犹新.如果今天(三年后)我不得不推荐任何东西来在Perl中进行漂亮的打印,我肯定会肯定使用数据::打印机.从数据::打印机自己的原理:

Edit (20120304): I had completely forgotten this question, but it was upvoted today and that jogged my memory. If I had to recommend anything today (3 years later) for pretty printing in Perl, I would certainly go with Data::Printer. From Data::Printer's own Rationale:

Data :: Dumper是一个很棒的工具,用于以适合于eval的方式对数据结构进行字符串化处理.

Data::Dumper is a fantastic tool, meant to stringify data structures in a way they are suitable for being eval'ed back in.

问题是,很多人继续使用它(以及类似的数据,例如Data :: Dump)在屏幕上打印数据结构和对象以进行检查和调试,而您可以使用这些模块,并不意味着您应该.

The thing is, a lot of people keep using it (and similar ones, like Data::Dump) to print data structures and objects on screen for inspection and debugging, and while you can use those modules for that, it doesn't mean mean you should.

这是Data :: Printer进入的地方.它只能做一件事情,一件事情: 在屏幕上以正确的格式在屏幕上显示Perl变量和对象(由人工检查)

This is where Data::Printer comes in. It is meant to do one thing and one thing only: display Perl variables and objects on screen, properly formatted (to be inspected by a human)