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