Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

  1. It is the only approach which allows you to directly serialize the nested hash strcture to file and back through a seamless interface.
  2. It is implemented in C which should give some performance advantage over the other two modules implemented in Perl.

 I  I have already tested this approach in JKFlow and it successfully marshalls and unmarshalls the complex nested hash based data strcutures in JKFlow by simply passing a reference to the root of the nested structure to its component sub-routines. Follwoing is the description of how to use the module.

Usage of the Storable Module 

Storable is a C extension module for serializing data directly to files and is the fastest of the three approaches. The store function takes a reference to a data structure (the root) and the name of a file. The retrieve method does the converse: given a filename, it returns the root:

Code Block

Code Block

Storable is a C extension module for serializing data directly to files and is the fastest of the three approaches. The store function takes a reference to a data structure (the root) and the name of a file. The retrieve method does the converse: given a filename, it returns the root:

use Storable;
$a = [100, 200, {'foo' => 'bar'}];
eval {
    store($a, 'test.dat');
};
print "Error writing to file: $@" if $@;
$a = retrieve('test.dat');

If

...

you

...

have

...

more

...

than

...

one

...

structure

...

to

...

stuff

...

into

...

a

...

file,

...

simply

...

put

...

all

...

of

...

them

...

in

...

an

...

anonymous

...

array

...

and

...

pass

...

this

...

array's

...

reference

...

to

...

store.

...

You

...

can

...

pass

...

an

...

open

...

filehandle

...

to

...

store_fd

...

instead

...

of

...

giving

...

a

...

filename

...

to

...

store.

...

The

...

functions

...

nstore

...

and

...

nstore_fd

...

can

...

be

...

used

...

for

...

storing

...

the

...

data

...

in

...

"network"

...

order,

...

making

...

the

...

data

...

machine-independent.

...

When

...

you

...

use

...

retrieve

...

or

...

retrieve_fd,

...

the

...

data

...

is

...

automatically

...

converted

...

back

...

to

...

the

...

native

...

machine

...

format

...

(while

...

storing,

...

the

...

module

...

storesa flag

...

indicating

...

whether

...

it

...

has

...

stored

...

it

...

in

...

a

...

machine-independent

...

format

...

or

...

not).

...