It should only dump the structure to the screen if -O=2 or less? See the lines that end in if $O <= 2;. There is something wrong with your copy of the code if this is not the case?
I added that so that I could quickly check that what got unpacked was the same as what was packed. For small examples only.
If you look a the third line of code you'll see: use Data::Dump qw[ pp ];; pp in this case stands for "pretty print" and is Data::Dump's equivalent of Data::Dumper's Dumper() function.
Okay. First off update your copy of the code from the original node where I've switched it from printf to print.
The guts of the thing is two calls to pack.
It goes through the array: @AoA (with $_ set to 0 .. $#AoA) one element at a time getting the reference to the sub-array.
The @{ ... } bit expands the array reference to the contents of that sub-array.
The pack format "V*" say pack all the values in the list (produced above), as unsigned integers into a binary string and return that string.
The second pack template "V/A*", says return the input binary string ("A*") prefixed ('/') with a 32-bit unsigned integer ('V').
And the print writes that out to the file.
As your sub-arrays are variable sized, we need the prefix count so that we know how much of the file to read back into each sub-array when retrieving it.
Note: You might prefer to use 'N' rather than 'V' if that is more natural on your platform.
In reply to Re^5: Storing large data structures on disk
by BrowserUk
in thread Storing large data structures on disk
by roibrodo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |