attribute[.attribute[..]] = value
Blank lines or lines starting with a # (hash-sign) will be ignored during parsing.
Lets construct an example optionfile for configuring cars and their attributes.
We call our optionfile "cars.properties" and it looks like this:
audi.tt.doors = 2 audi.tt.ps = 250 audi.a4.doors = 4 audi.a4.ps = 130 porsche.cayenne.doors = 4 porsche.boxter.doors = 2
Now you got two options.
my $psAudiA4 = $caropts->getProperty("audi.a4.ps");
my $caroptsStruct = $caropts->getCompleteConfig();
$caroptsStruct->{audi}->{tt}->{doors} = 2
$caroptsStruct->{audi}->{tt}->{ps} = 250
$caroptsStruct->{audi}->{a4}->{doors} = 4
$caroptsStruct->{audi}->{a4}->{ps} = 130
$caroptsStruct->{porsche}->{cayenne}->{doors} = 4
$caroptsStruct->{porsche}->{boxter}->{doors} = 2
#!/usr/bin/perl BEGIN { use strict; use warnings; use File::Spec; use File::Basename; use Data::Dumper; push(@INC, File::Spec->rel2abs(dirname($0))."/lib"); } use Merror; use Options; my $optfile = File::Spec->rel2abs(dirname($0))."/properties/cars.properties"; my $options = Options->new($optfile); if($options->{MERROR}->error()) { print("Error code: " . $options->{MERROR}->ec . "\n"); print("Error description: " . $options->{MERROR}->et . "\n"); print("Stacktrace:\n"); $options->{MERROR}->stacktrace; exit(0); } my $fullopts = $options->getCompleteConfig(); print Dumper($fullopts); my $audiA4Doors = $options->getProperty("audi.a4.doors"); print("Audi A4 doors: $audiA4Doors\n");
nexus@hoare: ~/src/perl/test$ ./test.pl
$VAR1 = {
'porsche' => {
'boxter' => {
'doors' => '2'
},
'cayenne' => {
'doors' => '4'
}
},
'audi' => {
'a4' => {
'doors' => '4',
'ps' => '130'
},
'tt' => {
'doors' => '2',
'ps' => '250'
}
}
};
Audi A4 doors: 4
Now lets assume that we got no read permissions on cars.properties
than the output will look like the following:
Error code: -1 Error description: Could not read option file: /home/nexus/src/perl/test/properties/cars.properties Stacktrace: Level: 0 -- File: /home/nexus/src/perl/test/lib/Merror.pm -- Pkg: Merror -- Sub: Merror::fillstack -- Line: 131 Level: 1 -- File: /home/nexus/src/perl/test/lib/Options.pm -- Pkg: Options -- Sub: Merror::error -- Line: 208 Level: 2 -- File: /home/nexus/src/perl/test/lib/Options.pm -- Pkg: Options -- Sub: Options::checkOptfile -- Line: 100 Level: 3 -- File: ./test.pl -- Pkg: main -- Sub: Options::new -- Line: 17
1.5.8