in reply to (DON'T) use Data::Dumper to implement Object persistence

Data::Dumper is too verbose and slow. It's ok for debugging, but to implement object persistence other modules like Storable are better suited.
  • Comment on Re: use Data::Dumper to implement Object persistence

Replies are listed 'Best First'.
Re^2: use Data::Dumper to implement Object persistence
by friedo (Prior) on Apr 27, 2005 at 21:45 UTC
    Here's a plug for my favorite serialization technique: YAML. It's not as fast as storable, but it's human readable (like D::D) and doesn't suffer from the security problems that evaling D::D has. And it's cross-platform; there are parsers and dumpers available for Python, PHP, C and Java.

    I had a job a couple years ago where we needed to share objects between some in-house mod_perl stuff, some third-party PHP stuff, and some Python stuff from a company we acquired. YAML made this trivial.

      OT but I dont see a C parser for YAML listed on the yaml.org website. If you know of one could you point it out please.
        I see no C parser for Data::Dumper's output either (other than perl itself!) and no C parser for Storable's output that is independent of perl either. But then, those don't really make any claim to be anything other than intimately tied to perl.

        YAML's lack of support in so many languages is, in my opinion, its biggest weakness. The lack of VB and C# implementations in particular is a Very Bad Thing. It's Very Bad because it makes XML the next best choice, and XML is Hateful.

Re^2: use Data::Dumper to implement Object persistence
by Tanktalus (Canon) on Apr 27, 2005 at 18:18 UTC

    Storable and Data::Dumper have their pros and cons. Data::Dumper is slow and verbose. Yes. Storable, however, is much more fragile. If I have two different versions of Storable, it'll be difficult to get them to talk to each other (e.g., persistance crossing upgrade boundaries, or jumping from machine to machine). Yet Data::Dumper works here just fine.

    Data::Dumper is nice in that it is completely upwards and downwards compatable. That costs - both in CPU speed, and space usage.