Re: A neat trick to serialize arrays and hashes

From: Ben Morrow (usenet_at_morrow.me.uk)
Date: 06/18/04


Date: Fri, 18 Jun 2004 04:35:55 +0000 (UTC)


Quoth jl_post@hotmail.com (J. Romano):
> 3. This technique only handles simple arrays and hashes.
> In other words, multi-dimensional arrays and hashes,
> lists of lists, an references are not handled
> correctly. If you really want to serialize a
> complex structure such as one of these, I recommend
> using another approach, like taking advantage of
> the Data::Dumper module. You CAN however, create
> an array of these serialized arrays, and serialize
> that array!

...however, you can't then unserialize it, as the references have been
stringified and can't be converted back to refs. Yet another reason the
use Storable, which does this right...

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


Relevant Pages

  • Re: Another Dereference Post by me
    ... Using the Schwartzian transform, each file's modification time ... perldoc perllol -- "Lists Of Lists", showing you how to create and use ... multidimensional arrays. ... lists", showing you how to construct arrays of hashes, hashes of arrays, ...
    (comp.lang.perl.misc)
  • Re: RAD vs. performance
    ... arrays and lists are iterable containers which, while correct, applies to ... the optimisation phase. ... trade-off in the situations where this abstraction is useful but I think ...
    (comp.lang.misc)
  • Re: Perl newbie q: trying to access array using variable name
    ... arrays, aka arrays of arrays (AoA in short, or LoL -- lists of lists). ... actually be hashes instead of arrays. ... we could give you even better directions on how to achieve that. ...
    (comp.lang.perl.misc)
  • Re: Compiler and an interpreter
    ... > Arrays are not more efficient than lists. ... > You should study the STL... ... For really complicate formulae, OCaml will be ...
    (comp.programming)
  • FAQ 4.39 What is the difference between a list and an array?
    ... This message is one of several periodic postings to comp.lang.perl.misc ... from the documentation provided with Perl. ... Subroutines are passed and return lists, ... context, you initialize arrays with lists, and you foreachacross a ...
    (comp.lang.perl.misc)

Loading