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 ๐Ÿ’…


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 Glib for 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