A
alfonsobaldaserra
hello group,
i understand that there are modules to parse and read .ini files but
just to understand data structures better i was playing with this.
the following code is from perl developers dictionary:
use strict;
use warnings;
use Data:
umper;
open my $fh, '<', "my.ini" or die "$!\n";
my $ini = {};
{
local $/ = "";
while (<$fh>) {
next unless ( s/\[([^]]+)\]// );
my $header = $1;
$ini->{$header} = {};
while (m/(\w+)=(.*)/g) {
$ini->{$header}->{$1} = $2;
}
}
}
close $fh;
print Dumper $ini;
__DATA__
[Build]
BuildID=20110209115208
Milestone=2.0b11
SourceStamp=f9d66f4d17bf
SourceRepository=http://hg.mozilla.org/mozilla-central
; This file is in the UTF-8 encoding
[Strings]
Title=SeaMonkey Update
Info=SeaMonkey is installing your updates and will start in a few
moments
i could not figure a way to do something like
print $ini->{Build}->{Milestone}
# 2.0b11
print $ini->{Strings}->{Title}
# SeaMonkey Update
could somebody lend me their hand to figure how to make this work?
thanks
i understand that there are modules to parse and read .ini files but
just to understand data structures better i was playing with this.
the following code is from perl developers dictionary:
use strict;
use warnings;
use Data:
open my $fh, '<', "my.ini" or die "$!\n";
my $ini = {};
{
local $/ = "";
while (<$fh>) {
next unless ( s/\[([^]]+)\]// );
my $header = $1;
$ini->{$header} = {};
while (m/(\w+)=(.*)/g) {
$ini->{$header}->{$1} = $2;
}
}
}
close $fh;
print Dumper $ini;
__DATA__
[Build]
BuildID=20110209115208
Milestone=2.0b11
SourceStamp=f9d66f4d17bf
SourceRepository=http://hg.mozilla.org/mozilla-central
; This file is in the UTF-8 encoding
[Strings]
Title=SeaMonkey Update
Info=SeaMonkey is installing your updates and will start in a few
moments
i could not figure a way to do something like
print $ini->{Build}->{Milestone}
# 2.0b11
print $ini->{Strings}->{Title}
# SeaMonkey Update
could somebody lend me their hand to figure how to make this work?
thanks