2

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?

Zaid
  • 36,680
  • 16
  • 86
  • 155
taw
  • 18,110
  • 15
  • 57
  • 76

3 Answers3

11

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.

Zaid
  • 36,680
  • 16
  • 86
  • 155
  • 1
    I know I'll catch flak, but I prefer Data::Dump to Data::Dumper. I guess it's just whatcha know and are used to. :-) – mswanberg Jun 30 '12 at 00:21
4

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

hobbs
  • 223,387
  • 19
  • 210
  • 288
0

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.

Oleg V. Volkov
  • 21,719
  • 4
  • 44
  • 68