Warning: Undefined array key "search_mode" in /home/bakers/html/search.php on line 27

Warning: Undefined array key "include_body" in /home/bakers/html/search.php on line 28

Warning: Undefined array key 1329 in /home/bakers/html/search.php on line 247

Warning: Undefined variable $search_results in /home/bakers/html/search.php on line 257

Warning: Undefined variable $start in /home/bakers/html/search.php on line 261

Warning: Undefined variable $message in /home/bakers/html/search.php on line 63

Warning: Undefined variable $output in /home/bakers/html/search.php on line 65
Perturb.org - interesting technology related things from around the internet

Showing entries with tag "ini".

Found 1 entries

Perl: Simple .ini parser

I wrote a simple .ini parsing function in Perl.

my $hash_ref = parse_ini("/tmp/config.ini");
sub parse_ini {
    open (my $INI, "<", $_[0]) or return undef;

    my $ret     = {};
    my $section = "_";

    while (my $line = readline($INI)) {
        if ($line =~ /^\[(.+?)\]/) { # Section heading
            $section = $1;
        } elsif ($line =~ /^(\w.*?)\s*=\s*"?(.*?)"?\s*$/) { # Key/Value pair
            $ret->{$section}->{$1} = $2;
        }
    }

    return $ret;
}
Leave A Reply