preferences file

J

Jack

hello,

have you a good way to examine a preferences file
with entries like this :

pref1=short
pref2=100
pref3=/tmp/file

thanks.
Regards,
 
U

Uri Guttman

J> have you a good way to examine a preferences file
J> with entries like this :

J> pref1=short
J> pref2=100
J> pref3=/tmp/file

use File::Slurp ;

my $pref_text = read_file( 'preferences' ) ;
my %prefs = $pref_text =~ m/^(\w+)=(.+)/gm ;

uri
 
A

Andres Monroy-Hernandez

hello,

have you a good way to examine a preferences file
with entries like this :

pref1=short
pref2=100
pref3=/tmp/file

thanks.
Regards,

You can open the file and parse it. For example:

sub read_preference {
# this function returns a hashref
# with the name-value pairs of the preference file
my ($file) = @_;
open(FH, $file) or die "Cannot open $file:$!";
my %pref;
while (<FH>) {
my ($name, $value) = split /=/; # assuming there are no ='s in the value
$pref{$name} = $value;
}
close (FH);
return \%pref;
}

-Andrés
 

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

No members online now.

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top