From 189d03d210a5e46239b4ac2afc5c0b280ca6b1be Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 23 Jun 2015 16:08:06 +0200 Subject: [PATCH] Inifile: alten Schrott beseitigt --- SL/Inifile.pm | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/SL/Inifile.pm b/SL/Inifile.pm index 43689d1c0..91af9fc79 100644 --- a/SL/Inifile.pm +++ b/SL/Inifile.pm @@ -45,50 +45,40 @@ sub new { my ($type, $file, %options) = @_; my $id = ""; - my $skip; + my $cur; - local *FH; + my $self = { FILE => $file, ORDER => [] }; - my $self = { "FILE" => $file }; + open my $fh, "$file" or $::form->error("$file : $!"); - open FH, "$file" or $::form->error("$file : $!"); - - while () { + for (<$fh>) { chomp; if (!$options{verbatim}) { # strip comments - s/\#.*//; - # remove any trailing whitespace + s/\s*#.*$//; s/^\s*//; - s/\s*$//; } else { - next if (m/^\s*\#/); + next if m/#/; } next unless $_; - if (m/^\[/) { - s/(\[|\])//g; - - $id = $_; - - $self->{$id} ||= { }; + if (m/^\[(.*)\]$/) { + $id = $1; + $cur = $self->{$1} ||= { }; - push @{ $self->{ORDER} }, $_; - - next; + push @{ $self->{ORDER} }, $1; + } else { + # add key=value to $id + my ($key, $value) = split m/=/, $_, 2; + $cur->{$key} = $value; } - # add key=value to $id - my ($key, $value) = split m/=/, $_, 2; - - $self->{$id}->{$key} = $value; - } - close FH; + close $fh; $main::lxdebug->leave_sub(2); -- 2.20.1