Module for user preferences ~/. file

T

traggatt

Hi

Does anyone know a module which will store/retreive user preferences
into a ~/.scriptprefs type file (e.g. like ~/.bashrc)?

Cheers
Tim
 
A

anno4000

Hi

Does anyone know a module which will store/retreive user preferences
into a ~/.scriptprefs type file (e.g. like ~/.bashrc)?

It isn't quite clear what you mean with "store/retrieve". For a
start take a look at the File::Tie module.

Anno
 
T

traggatt

It isn't quite clear what you mean with "store/retrieve". For a
start take a look at the File::Tie module.

Sorry, I mean more of the retrieve really. I would like to store
preferences in a file with a format like this:

UserName tim
Password timspassword
DefaultHost timbox

etc...

This file could be created manually by the user. When executed, my Perl
script would look for the file and automatically load in these
preferences.

I had a look at the File::Tie module and it seems it would load the
file contents ok, but what could I use to parse the file's contents?

Cheers, Tim.
 
A

anno4000

Sorry, I mean more of the retrieve really. I would like to store
preferences in a file with a format like this:

UserName tim
Password timspassword

In plain text? Very bad idea. Let the user enter the password
manually when needed. Security and convenience are a trade-off.
DefaultHost timbox

etc...

This file could be created manually by the user. When executed, my Perl
script would look for the file and automatically load in these
preferences.

I had a look at the File::Tie module and it seems it would load the
file contents ok, but what could I use to parse the file's contents?

File::Tie doesn't have special advantages for what you describe now.
You can still use it, of course.

Your file format looks like a list of name/value pairs, one per line.
That maps naturally to a Perl hash, call it %pref. The split function
can be used to parse the lines (untested):

my %pref;
while ( <$in> ) {
my ( $name, $value) = split $_, ' ', 2;
$pref{ $name} = $value;
}

Later you can access $pref{ UserName} to get the corresponding value.

It would be a good idea to allow comments and blank lines in the
file format.

Anno
 
H

Henry Law

Does anyone know a module which will store/retreive user preferences
into a ~/.scriptprefs type file (e.g. like ~/.bashrc)?

I use a simple XML file for this, and XML::Simple to read it in and save
it back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top