PDL::IO::Dumper(3pm)

πŸ’– PDL::IO::Dumper πŸ’–

okay bestie, listen β€” this is the PDL::IO::Dumper page, and it's genuinely one of the good ones. no cap.


🌸 NAME 🌸

PDL::IO::Dumper β€” data dumping, but make it structs with PDLs. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

So basically: this package lets you cleanly save and restore complex data structures that happen to have PDLs in them, as ASCII strings and/or transportable ASCII files. It's giving ✨portable✨ and we're obsessed. 🫢

It exports four functions straight into your namespace: sdump, fdump, frestore, and deep_copy.

Here's the tea: PDL::IO::Dumper walks the same types of structure that Data::Dumper knows about, because β€” plot twist β€” it literally uses a call to Data::Dumper under the hood. BUT. And this is the important part. Unlike Data::Dumper, it doesn't crash when it goes accessing PDLs. slay. πŸ’…

The PDL::IO::Dumper routines have a slightly different syntax than Data::Dumper does: you may only dump a single scalar perl expression rather than an arbitrary one. Of course, that scalar can be a ref to whatever humongous pile of spaghetti you want, so honestly? that's no big loss. 🍝

The output string is intended to be about as readable as Dumper's output is for non-PDL expressions. To that end:

  • small PDLs (up to 8 elements) β†’ stored as inline perl expressions
  • midsized PDLs (up to 200 elements) β†’ stored as perl expressions above the main data structure
  • large PDLs β†’ stored as FITS files that are uuencoded and included in the dump string

And ngl, no attempt is made to shrink the output string whatsoever β€” for example, inlined PDL expressions all include explicit reshape() and typecast commands, and uuencoding expands stuff by a factor of about 1.5. So yeah, your data structures will grow when you dump them. it's giving inflation 😭

πŸ’€ Bugs πŸ’€

It's still possible to break this code and cause it to dump core, for the same reason that Data::Dumper crashes. In particular, other external-hook variables aren't recognized (for that a more universal Dumper would be needed) and will still exercise the Data::Dumper crash. This is by choice, bestie:

  • (A) it's difficult to recognize which objects are actually external
  • (B) most everyday objects are quite safe

Another shortfall of Data::Dumper is that it doesn't recognize tied objects. This might be a Good Thing or a Bad Thing depending on your point of view, but it means that PDL::IO::Dumper includes a kludge to handle the tied Astro::FITS::Header objects associated with FITS headers (see the rfits documentation in PDL::IO::Misc for details). iykyk πŸ“Ž

Also there's currently no reference recursion detection, so a non-treelike reference topology will cause Dumper to buzz forever 😭 πŸ”₯ That will likely be fixed in a future version. Meanwhile a warning message finds likely cases. consider yourself warned babes 🫢


πŸŽ€ FUNCTIONS πŸŽ€

✨ sdump ✨

Dump a data structure to a string.

use PDL::IO::Dumper;
$s = sdump(<VAR>);
...
<VAR> = eval $s;

sdump dumps a single complex data structure into a string. You restore the data structure by eval-ing the string. Since eval is a builtin, no convenience routine exists to use it. (she's low maintenance like that πŸ’…)

✨ fdump ✨

Dump a data structure to a file

use PDL::IO::Dumper;
fdump(<VAR>,$filename);
...
<VAR> = frestore($filename);

fdump dumps a single complex data structure to a file. You restore the data structure by eval-ing the perl code put in the file. A convenience routine (frestore) exists to do it for you. 🫢

I suggest using the extension .pld or (for non-broken OS's) .pdld to distinguish Dumper files. That way they are reminiscent of .pl files for perl, while still looking a little different so you can pick them out. You can certainly feed a dump file straight into perl (for syntax checking) but it will not do much for you, just build your data structure and exit. iconic, honestly πŸ‘‘

✨ frestore ✨

Restore a dumped file

use PDL::IO::Dumper;
fdump(<VAR>,$filename);
...
<VAR> = frestore($filename);

frestore() is a convenience function that just reads in the named file and executes it in an eval. It's paired with fdump(). they're a duo, they're a package deal πŸ’ž

✨ deep_copy ✨

Convenience function copies a complete perl data structure by the brute force method of "eval sdump". no thoughts, just vibes 🧚

✨ PDL::IO::Dumper::big_PDL ✨

Identify whether a PDL is ``big'' [Internal routine]

Internal routine takes a PDL and returns a boolean indicating whether it's small enough for direct insertion into the dump string. If 0, it can be inserted. Larger numbers yield larger scopes of PDL. 1 implies that it should be broken out but can be handled with a couple of perl commands; 2 implies full uudecode treatment.

PDLs with Astro::FITS::Header objects as headers are taken to be FITS files and are always treated as huge, regardless of size. size is a construct anyway πŸ’…

✨ PDL::IO::Dumper::stringify_PDL ✨

Turn a PDL into a 1-part perl expr [Internal routine]

Internal routine that takes a PDL and returns a perl string that evals to the PDL. It should be used with care because it doesn't dump headers and it doesn't check number of elements. The point here is that numbers are dumped with the correct precision for their storage class. Things we don't know about get stringified element-by-element by their builtin class, which is probably not a bad guess. honestly? fair. πŸ™ˆ

✨ PDL::IO::Dumper::uudecode_PDL ✨

Recover a PDL from a uuencoded string [Internal routine]

This routine encapsulates uudecoding of the dumped string for large ndarrays. she decodes πŸ’…

✨ PDL::IO::Dumper::dump_PDL ✨

Generate 1- or 2-part expr for a PDL [Internal routine]

Internal routine that produces commands defining a PDL. You supply (<PDL>, <name>) and get back two strings: a prepended command string and an expr that evaluates to the final PDL. PDL is the PDL you want to dump. <inline> is a flag whether dump_PDL is being called inline or before the inline dump string (0 for before; 1 for in). <name> is the name of the variable to be assigned (for medium and large PDLs, which are defined before the dump string and assigned unique IDs).

✨ PDL::IO::Dumper::find_PDLs ✨

Walk a data structure and dump PDLs [Internal routine]

Walks the original data structure and generates appropriate exprs for each PDL. The exprs are inserted into the Data::Dumper output string. You shouldn't call this unless you know what you're doing. (see sdump, above). πŸ”₯


πŸ’œ AUTHOR πŸ’œ

Copyright 2002, Craig DeForest.

This code may be distributed under the same terms as Perl itself (license available at <http://www.perl.org>). Copying, reverse engineering, distribution, and modification are explicitly allowed so long as this notice is preserved intact and modified versions are clearly marked as such. periodt ✨

This package comes with NO WARRANTY. bestie you are on your own, no takebacks πŸ™ˆ


k that's the whole page, you ate it up fr fr πŸ’– go dump something huge and read it back, you got this 🫢

β€” written by your girl, running on perl v5.42.3, dated 2026-08-20, straight out of the PDL::IO::Dumper(3pm) manual. byeee 🌈⭐

πŸ“¦ where this page comes from