28 November 2009

 

Parse .ini to Hash

sub IniLoad {
 # my %ini = &IniLoad("/where/is/file.ini");
 # print $ini{"section:field"};
 my $file=shift; my %ini; my @INI = &tacoenf::load_as_array($file);
 for $l(@INI) {
  $l=tacoenf::notrail($l);
  if ($l=~/^\[(.*)\]/) {
   $vsection = $l; $vsection =~ s/^\[(.*)\]$/$1/ie;
  }
  next if ($l eq "");
  next if ($l=~/^\[(.*)\]/);
  my $value=$vkey=$l;
  $vkey =~ s/(.*)\=(.*)/$1/gie; $vkey=tacoenf::trim($vkey);
  $value=~ s/(.*)\=(.*)/$2/gie; $value=tacoenf::trim($value);
  $ini{"$vsection:$vkey"} = $value;
 }
 return %ini

}

#A Shortcut
sub IniRead {
 my($file,$section,$key)=@_;
 my %ini = &IniLoad("where/is/file.ini");
 return $ini{"$section:$key"};
}
require tacoen.pm

Label: ,


Arsip

Januari 2009   Oktober 2009   November 2009   Maret 2010   Januari 2011   Februari 2011   Juli 2011   Juni 2012