Glib::KeyFile(3)
โจ Glib::KeyFile(3) โ your .ini-like parser bestie ๐
okay so welcome to the User Contributed Perl Documentation page for Glib::KeyFile(3). If you've ever wanted to parse, edit, or create .ini-style key files in Perl, this is literally your moment. We're doing the whole thing together โ every signature, every param, every croak, no skips, no cap โจ๐ซถ
โจ NAME โจ
Glib::KeyFile - Parser for .ini-like files ๐
โจ SYNOPSIS โจ
okay so here's the whole vibe โ exact synopsis, bestie, no edits:
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
โจ DESCRIPTION โจ
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, and here's a quick summary: key files consist of groups of key-value pairs, interspersed with comments. periodt ๐
โจ METHODS โจ
โจ keyfile = Glib::KeyFile->new โจ
Fresh key file, no args, constructor vibes. That's the whole entry on this one. ๐
โจ boolean = $key_file->get_boolean ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves a boolean value from $key inside $group_name. ๐ซถ
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ list = $key_file->get_boolean_list ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves a list of booleans from $key inside $group_name. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->set_boolean_list ($group_name, $key, ...) โจ
$group_name(string)$key(string)...(list) list of booleans
Sets a list of booleans in $key inside $group_name. If $key cannot be found then it is created. If $group_name cannot be found then it is created. ๐
โจ $key_file->set_boolean ($group_name, $key, $value) โจ
$group_name(string)$key(string)$value(boolean)
Sets a boolean value to $key inside $group_name. If $key is not found, it is created. โจ
โจ string = $key_file->get_comment ($group_name=undef, $key=undef) โจ
$group_name(string or undef)$key(string or undef)
Grabs a comment above $key from $group_name. If $key is undef then $comment will be read from above $group_name. If both $key and $group_name are undef, then $comment will be read from above the first group in the file. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->set_comment ($group_name, $key, $comment) โจ
$group_name(string or undef)$key(string or undef)$comment(string)
Places a comment above $key from $group_name. If $key is undef then $comment will be written above $group_name. If both $key and $group_name are undef, then $comment will be written above the first group in the file. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ double = $key_file->get_double ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves a double value from $key inside $group_name. ๐ฅ
May croak with a Glib::Error in $@ on failure. ๐ญ
Since: glib 2.12
โจ list = $key_file->get_double_list ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves a list of doubles from $key inside $group_name. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
Since: glib 2.12
โจ $key_file->set_double_list ($group_name, $key, ...) โจ
$group_name(string)$key(string)...(list) list of doubles
Sets a list of doubles in $key inside $group_name. If $key cannot be found then it is created. If $group_name cannot be found then it is created. โจ
Since: glib 2.12
โจ $key_file->set_double ($group_name, $key, $value) โจ
$group_name(string)$key(string)$value(double)
Sets a double value to $key inside $group_name. If $key is not found, it is created. ๐ซ
Since: glib 2.12
โจ list = $key_file->get_groups โจ
Returns the list of groups inside the key_file. ๐ซถ
โจ boolean = $key_file->has_group ($group_name) โจ
$group_name(string)
Checks whether $group_name is present in $key_file. ๐
โจ boolean = $key_file->has_key ($group_name, $key) โจ
$group_name(string)$key(string)
Checks whether $group_name has $key in it. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ integer = $key_file->get_integer ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves an integer value from $key inside $group_name. ๐ข
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ list = $key_file->get_integer_list ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves a list of integers from $key inside $group_name. ๐งฎ
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->set_integer_list ($group_name, $key, ...) โจ
$group_name(string)$key(string)...(list) list of integers
Sets a list of doubles in $key inside $group_name. If $key cannot be found then it is created. If $group_name cannot be found then it is created.
okay bestie, the original text lowkey says "doubles" for set_integer_list โ I'm keeping it exactly, don't come for me ๐
โจ $key_file->set_integer ($group_name, $key, $value) โจ
$group_name(string)$key(string)$value(integer)
Sets an integer value to $key inside $group_name. If $key is not found, it is created. โจ
โจ list = $key_file->get_keys ($group_name) โจ
$group_name(string)
Returns the list of keys inside a group of the key file. ๐๏ธ
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->set_list_separator ($separator) โจ
$separator(string)
Sets the list separator character. ๐๏ธ
โจ boolean = $key_file->load_from_data ($buf, $flags) โจ
$buf(scalar)$flags(Glib::KeyFileFlags)
Parses a string containing a key file structure. ๐ง
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ boolean = $key_file->load_from_data_dirs ($file, $flags) or (boolean, scalar) = $key_file->load_from_data_dirs ($file, $flags) โจ
$file(string)$flags(Glib::KeyFileFlags)
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. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ boolean = $key_file->load_from_dirs ($file, $flags, @search_dirs) or (boolean, scalar) = $key_file->load_from_dirs ($file, $flags, @search_dirs) โจ
$file(string)$flags(Glib::KeyFileFlags)...(list)
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. ๐ซ
May croak with a Glib::Error in $@ on failure. ๐ญ
Since: glib 2.14
โจ boolean = $key_file->load_from_file ($file, $flags) โจ
$file(string)$flags(Glib::KeyFileFlags)
Parses a key file. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ string = $key_file->get_locale_string ($group_name, $key, $locale=undef) โจ
$group_name(string)$key(string)$locale(string or undef)
Returns the value associated with $key under $group_name translated in the given $locale if available. If $locale is undef then the current locale is assumed. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ list = $key_file->get_locale_string_list ($group_name, $key, $locale) โจ
$group_name(string)$key(string)$locale(string)
That's the whole description the page gives us, bestie โ just the params and the croak note. ๐ซถ
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->set_locale_string_list ($group_name, $key, $locale, ...) โจ
$group_name(string)$key(string)$locale(string)...(list)
Associates a list of string values for $key and $locale under $group_name. If the translation for $key cannot be found then it is created. ๐
โจ $key_file->set_locale_string ($group_name, $key, $locale, $string) โจ
$group_name(string)$key(string)$locale(string)$string(string)
Signature and params only โ no extra description on the page, mysterious main character energy. โจ
โจ $key_file->remove_comment ($group_name=undef, $key=undef) โจ
$group_name(string or undef)$key(string or undef)
Removes a comment from a group in a key file. If $key is undef, the comment will be removed from above $group_name. If both $key and $group_name are undef, the comment will be removed from the top of the key file. ๐งน
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->remove_group ($group_name) โจ
$group_name(string)
Removes a group from a key file. ๐๏ธ
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->remove_key ($group_name, $key) โจ
$group_name(string)$key(string)
Removes a key from $group_name. โ๏ธ
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ string = $key_file->get_start_group โจ
Returns the first group inside a key file. ๐ฅ
โจ string = $key_file->get_string ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves a string value from $key inside $group_name. ๐งต
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ list = $key_file->get_string_list ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves a list of strings from $key inside $group_name. ๐ธ
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->set_string_list ($group_name, $key, ...) โจ
$group_name(string)$key(string)...(list) list of strings
Sets a list of strings in $key inside $group_name. The strings will be escaped if they contain special characters. If $key cannot be found then it is created. If $group_name cannot be found then it is created. ๐
โจ $key_file->set_string ($group_name, $key, $value) โจ
$group_name(string)$key(string)$value(string)
Sets a string value to $key inside $group_name. The string will be escaped if it contains special characters. If $key is not found, it is created. โจ
โจ string = $key_file->to_data โจ
Returns the key file as a string. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ string = $key_file->get_value ($group_name, $key) โจ
$group_name(string)$key(string)
Retrieves the literal value of $key inside $group_name. ๐
May croak with a Glib::Error in $@ on failure. ๐ญ
โจ $key_file->set_value ($group_name, $key, $value) โจ
$group_name(string)$key(string)$value(string)
Sets the literal value of $key inside $group_name. If $key cannot be found, it is created. If $group_name cannot be found, it is created. ๐
โจ ENUMS AND FLAGS โจ
โจ flags Glib::KeyFileFlags โจ
'none'/'G_KEY_FILE_NONE''keep-comments'/'G_KEY_FILE_KEEP_COMMENTS''keep-translations'/'G_KEY_FILE_KEEP_TRANSLATIONS'
๐ SEE ALSO ๐
Okay bestie, when you're done here and you wanna go deeper down the rabbit hole ๐ โ go check out:
Glibโ that's the mothership, the whole big-picture module this one lives inside ๐ซถ
That's it, that's the whole list. Short and iconic, honestly ๐
๐ COPYRIGHT ๐
Legal moment, no cap โ gotta say it loud and clear โจ
- Copyright (C) 2003-2011 by the gtk2-perl team. ๐
- This software is licensed under the LGPL. See
Glibfor a full notice. ๐
Fr fr, if you're planning to redistribute or build on this, actually go read that license notice in Glib โ it's giving "read the fine print" energy for a reason ๐
And that's a wrap on this lil page, bestie ๐ You made it to the very end โ main character energy fr fr ๐ This one's from perl v5.42.0, dated 2023-09-05 โ oldie but a goodie, still slaying ๐ Go forth and parse those key files like the icon you are ๐โจ๐ฆ
๐ฆ where this page comes from
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 ยท LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 ยท LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 ยท LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 ยท LGPL-2.1-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms