Is there a less verbose alternative to Perl's Data::Dumper?

青春壹個敷衍的年華 提交于 2019-12-11 00:59:53

问题


I'm trying to print some parse trees, and Data::Dumper is very verbose for that, for example printing:

{
  'A' => {
    'ID' => 'y'
  },
  'OP' => '=',
  'B' => {
    'NUM' => '5'
  }
},

rather than let's say:

{
  'A' => {'ID' => 'y'},
  'OP' => '=',
  'B' => {'NUM' => '5'}
},

and it's very hard to read since it take massive number of lines.

Is there any Perl library which does what Data::Dumper does except more tersely, or do I need to write my own?


回答1:


You want Data::Dump :

HISTORY

The Data::Dump module grew out of frustration with Sarathy's in-most-cases-excellent Data::Dumper. Basic ideas and some code are shared with Sarathy's module. The Data::Dump module provides a much simpler interface than Data::Dumper.

Data::Printer is a more modern alternative with colored output.




回答2:


You mean besides Data::Dumper::Concise? :)




回答3:


If using $Data::Dumper::Indent is not enough, you may like to try JSON or YAML module families, if you only need data to be human-readable (i.e. for debugging). Their format is close enough to Perl's own to read easily and they have many formatting options.



来源:https://stackoverflow.com/questions/11261854/is-there-a-less-verbose-alternative-to-perls-datadumper

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!