use Glib; $data .= $_ while (<DATA>); $f = Glib::KeyFile->new; $f->load_from_data($data); if ($f->has_group('Main') && $f->has_key('Main', 'someotherkey')) { $val = $f->get_integer('Main', 'someotherkey'); print $val . "\n"; } 0; __DATA__ # a comment [MainSection] somekey=somevalue someotherkey=42 someboolkey=true listkey=1;1;2;3;5;8;13;21 localekey=Good Morning localekey[it]=Buon giorno localekey[es]=Buenas dias localekey[fr]=Bonjour
Glib::KeyFile lets you parse, edit or create files containing groups of key-value pairs, which we call key files for lack of a better name. Several freedesktop.org specifications use key files now, e.g the Desktop Entry Specification and the Icon Theme Specification.
The syntax of key files is described in detail in the Desktop Entry Specification, here is a quick summary: Key files consists of groups of key-value pairs, interspersed with comments.
Parses a key file, searching for it inside the specified directories. In scalar context, it returns a boolean value (true on success, false otherwise); in array context, it returns a boolean value and the full path of the file.
Parses a key file, searching for it inside the data directories. In scalar context, it returns a boolean value (true on success, false otherwise); in array context, it returns a boolean value and the full path of the file.
To install Glib, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Glib
CPAN shell
perl -MCPAN -e shell install Glib
For more information on module installation, please visit the detailed CPAN module installation guide.