Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Any module for saving data as perl data?

by Discipulus (Canon)
on Apr 29, 2016 at 07:27 UTC ( [id://1161854]=note: print w/replies, xml ) Need Help??


in reply to Any module for saving data as perl data?

Storable is a core module since ever. It does exactly what you ask for. See it's synopsis for examples.

Data::Dumper is another core module that can store Perl's data to disk.

In addition many other modules can store Perl datastructures into a file and retrieve them later: for example YAML

Every module has some limitation or feature: read a this thread where afoken describes Data::Dumper JSON Storable YAML differences and others point to other possibilies to accomplish with your task.

update: In the above thread i point to Sereal-Comparison-Graphs which can be intersting too, being Sereal a worth to try module.

I used to convert a a datastructure (an array) from Storable to YAML and viceversa with two simple oneliners:

# WARNING windows quotes # storable to yaml perl -MYAML -MStorable -e "print Dump @{retrieve ($ARGV[0])};" # yaml to storable perl -e "use YAML (LoadFile); use Storable qw(nstore); @ar = LoadFile( +$ARGV[0]); nstore(\@ar, $ARGV[1])"

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1161854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found