Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: A good way to input data into a script w/o an SQL database

by Discipulus (Canon)
on Sep 11, 2023 at 07:24 UTC ( [id://11154365] : note . print w/replies, xml ) Need Help??


in reply to A good way to input data into a script w/o an SQL database

Hello ObiPanda,

you already got very good answer, but, strange to me, some option was not mentioned.

Storable is a core module perfectly suited to load perl data structures from file. I have two command saved to read between Storable and YAML:

sto2yaml=perl -MYAML -MStorable -e "print Dump @{retrieve ($ARGV[0])}; +" $* yaml2sto=perl -e "use YAML (LoadFile); use Storable qw(nstore); @ar = +LoadFile($ARGV[0]); nstore(\@ar, $ARGV[1])" $*

Also Data::Dumper is a core module able to store and retrieve perl datastructures.

Then there is also Sereal a CPAN module offering great performances.

If you are only interested in something like an external configuration you can find fun my Modules as configuration files

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.

Replies are listed 'Best First'.
Re^2: A good way to input data into a script w/o an SQL database
by GrandFather (Saint) on Sep 11, 2023 at 09:36 UTC

    These are great for serialising Perl data structures out to disk then reading them back in later, but not so great for hand editing some options and not so great for recording in a revision control system.

    As it turns out the OP is working with text data so something like JSON, YAML or even .inf files are likely to be a better match.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond