1Glib::KeyFile(3) User Contributed Perl Documentation Glib::KeyFile(3)
2
3
4
6 Glib::KeyFile - Parser for .ini-like files
7
9 use Glib;
10
11 $data .= $_ while (<DATA>);
12
13 $f = Glib::KeyFile->new;
14 $f->load_from_data($data);
15 if ($f->has_group('Main') && $f->has_key('Main', 'someotherkey')) {
16 $val = $f->get_integer('Main', 'someotherkey');
17 print $val . "\n";
18 }
19 0;
20 __DATA__
21 # a comment
22 [MainSection]
23 somekey=somevalue
24 someotherkey=42
25 someboolkey=true
26 listkey=1;1;2;3;5;8;13;21
27 localekey=Good Morning
28 localekey[it]=Buon giorno
29 localekey[es]=Buenas dias
30 localekey[fr]=Bonjour
31
33 Glib::KeyFile lets you parse, edit or create files containing groups of
34 key-value pairs, which we call key files for lack of a better name.
35 Several freedesktop.org specifications use key files now, e.g the
36 Desktop Entry Specification and the Icon Theme Specification.
37
38 The syntax of key files is described in detail in the Desktop Entry
39 Specification, here is a quick summary: Key files consists of groups of
40 key-value pairs, interspersed with comments.
41
43 keyfile = Glib::KeyFile->new
44 boolean = $key_file->get_boolean ($group_name, $key)
45 · $group_name (string)
46
47 · $key (string)
48
49 Retrieves a boolean value from $key inside $group_name.
50
51 May croak with a Glib::Error in $@ on failure.
52
53 list = $key_file->get_boolean_list ($group_name, $key)
54 · $group_name (string)
55
56 · $key (string)
57
58 Retrieves a list of booleans from $key inside $group_name.
59
60 May croak with a Glib::Error in $@ on failure.
61
62 $key_file->set_boolean_list ($group_name, $key, ...)
63 · $group_name (string)
64
65 · $key (string)
66
67 · ... (list) list of booleans
68
69 Sets a list of booleans in $key inside $group_name. If $key cannot be
70 found then it is created. If $group_name cannot be found then it is
71 created.
72
73 $key_file->set_boolean ($group_name, $key, $value)
74 · $group_name (string)
75
76 · $key (string)
77
78 · $value (boolean)
79
80 Sets a boolean value to $key inside $group_name. If $key is not found,
81 it is created.
82
83 string = $key_file->get_comment ($group_name=undef, $key=undef)
84 · $group_name (string or undef)
85
86 · $key (string or undef)
87
88 Retreives a comment above $key from $group_name. If $key is undef then
89 $comment will be read from above $group_name. If both $key and
90 $group_name are undef, then $comment will be read from above the first
91 group in the file.
92
93 May croak with a Glib::Error in $@ on failure.
94
95 $key_file->set_comment ($group_name, $key, $comment)
96 · $group_name (string or undef)
97
98 · $key (string or undef)
99
100 · $comment (string)
101
102 Places a comment above $key from $group_name. If $key is undef then
103 $comment will be written above $group_name. If both $key and
104 $group_name are undef, then $comment will be written above the first
105 group in the file.
106
107 May croak with a Glib::Error in $@ on failure.
108
109 double = $key_file->get_double ($group_name, $key)
110 · $group_name (string)
111
112 · $key (string)
113
114 Retrieves a double value from $key inside $group_name.
115
116 May croak with a Glib::Error in $@ on failure.
117
118 Since: glib 2.12
119
120 list = $key_file->get_double_list ($group_name, $key)
121 · $group_name (string)
122
123 · $key (string)
124
125 Retrieves a list of doubles from $key inside $group_name.
126
127 May croak with a Glib::Error in $@ on failure.
128
129 Since: glib 2.12
130
131 $key_file->set_double_list ($group_name, $key, ...)
132 · $group_name (string)
133
134 · $key (string)
135
136 · ... (list) list of doubles
137
138 Sets a list of doubles in $key inside $group_name. If $key cannot be
139 found then it is created. If $group_name cannot be found then it is
140 created.
141
142 Since: glib 2.12
143
144 $key_file->set_double ($group_name, $key, $value)
145 · $group_name (string)
146
147 · $key (string)
148
149 · $value (double)
150
151 Sets a double value to $key inside $group_name. If $key is not found,
152 it is created.
153
154 Since: glib 2.12
155
156 list = $key_file->get_groups
157 Returns the list of groups inside the key_file.
158
159 boolean = $key_file->has_group ($group_name)
160 · $group_name (string)
161
162 Checks whether $group_name is present in $key_file.
163
164 boolean = $key_file->has_key ($group_name, $key)
165 · $group_name (string)
166
167 · $key (string)
168
169 Checks whether $group_name has $key in it.
170
171 May croak with a Glib::Error in $@ on failure.
172
173 integer = $key_file->get_integer ($group_name, $key)
174 · $group_name (string)
175
176 · $key (string)
177
178 Retrieves an integer value from $key inside $group_name.
179
180 May croak with a Glib::Error in $@ on failure.
181
182 list = $key_file->get_integer_list ($group_name, $key)
183 · $group_name (string)
184
185 · $key (string)
186
187 Retrieves a list of integers from $key inside $group_name.
188
189 May croak with a Glib::Error in $@ on failure.
190
191 $key_file->set_integer_list ($group_name, $key, ...)
192 · $group_name (string)
193
194 · $key (string)
195
196 · ... (list) list of integers
197
198 Sets a list of doubles in $key inside $group_name. If $key cannot be
199 found then it is created. If $group_name cannot be found then it is
200 created.
201
202 $key_file->set_integer ($group_name, $key, $value)
203 · $group_name (string)
204
205 · $key (string)
206
207 · $value (integer)
208
209 Sets an integer value to $key inside $group_name. If $key is not
210 found, it is created.
211
212 list = $key_file->get_keys ($group_name)
213 · $group_name (string)
214
215 Returns the list of keys inside a group of the key file.
216
217 May croak with a Glib::Error in $@ on failure.
218
219 $key_file->set_list_separator ($separator)
220 · $separator (string)
221
222 Sets the list separator character.
223
224 boolean = $key_file->load_from_data ($buf, $flags)
225 · $buf (scalar)
226
227 · $flags (Glib::KeyFileFlags)
228
229 Parses a string containing a key file structure.
230
231 May croak with a Glib::Error in $@ on failure.
232
233 boolean = $key_file->load_from_data_dirs ($file, $flags)
234 (boolean, scalar) = $key_file->load_from_data_dirs ($file, $flags)
235 · $file (string)
236
237 · $flags (Glib::KeyFileFlags)
238
239 Parses a key file, searching for it inside the data directories. In
240 scalar context, it returns a boolean value (true on success, false
241 otherwise); in array context, it returns a boolean value and the full
242 path of the file.
243
244 May croak with a Glib::Error in $@ on failure.
245
246 boolean = $key_file->load_from_dirs ($file, $flags, @search_dirs)
247 (boolean, scalar) = $key_file->load_from_dirs ($file, $flags, @search_dirs)
248 · $file (string)
249
250 · $flags (Glib::KeyFileFlags)
251
252 · ... (list)
253
254 Parses a key file, searching for it inside the specified directories.
255 In scalar context, it returns a boolean value (true on success, false
256 otherwise); in array context, it returns a boolean value and the full
257 path of the file.
258
259 May croak with a Glib::Error in $@ on failure.
260
261 Since: glib 2.14
262
263 boolean = $key_file->load_from_file ($file, $flags)
264 · $file (string)
265
266 · $flags (Glib::KeyFileFlags)
267
268 Parses a key file.
269
270 May croak with a Glib::Error in $@ on failure.
271
272 string = $key_file->get_locale_string ($group_name, $key, $locale=undef)
273 · $group_name (string)
274
275 · $key (string)
276
277 · $locale (string or undef)
278
279 Returns the value associated with $key under $group_name translated in
280 the given $locale if available. If $locale is undef then the current
281 locale is assumed.
282
283 May croak with a Glib::Error in $@ on failure.
284
285 list = $key_file->get_locale_string_list ($group_name, $key, $locale)
286 · $group_name (string)
287
288 · $key (string)
289
290 · $locale (string)
291
292 May croak with a Glib::Error in $@ on failure.
293
294 $key_file->set_locale_string_list ($group_name, $key, $locale, ...)
295 · $group_name (string)
296
297 · $key (string)
298
299 · $locale (string)
300
301 · ... (list)
302
303 Associates a list of string values for $key and $locale under
304 $group_name. If the translation for $key cannot be found then it is
305 created.
306
307 $key_file->set_locale_string ($group_name, $key, $locale, $string)
308 · $group_name (string)
309
310 · $key (string)
311
312 · $locale (string)
313
314 · $string (string)
315
316 $key_file->remove_comment ($group_name=undef, $key=undef)
317 · $group_name (string or undef)
318
319 · $key (string or undef)
320
321 Removes a comment from a group in a key file. If $key is undef, the
322 comment will be removed from above $group_name. If both $key and
323 $group_name are undef, the comment will be removed from the top of the
324 key file.
325
326 May croak with a Glib::Error in $@ on failure.
327
328 $key_file->remove_group ($group_name)
329 · $group_name (string)
330
331 Removes a group from a key file.
332
333 May croak with a Glib::Error in $@ on failure.
334
335 $key_file->remove_key ($group_name, $key)
336 · $group_name (string)
337
338 · $key (string)
339
340 Removes a key from $group_name.
341
342 May croak with a Glib::Error in $@ on failure.
343
344 string = $key_file->get_start_group
345 Returns the first group inside a key file.
346
347 string = $key_file->get_string ($group_name, $key)
348 · $group_name (string)
349
350 · $key (string)
351
352 Retrieves a string value from $key inside $group_name.
353
354 May croak with a Glib::Error in $@ on failure.
355
356 list = $key_file->get_string_list ($group_name, $key)
357 · $group_name (string)
358
359 · $key (string)
360
361 Retrieves a list of strings from $key inside $group_name.
362
363 May croak with a Glib::Error in $@ on failure.
364
365 $key_file->set_string_list ($group_name, $key, ...)
366 · $group_name (string)
367
368 · $key (string)
369
370 · ... (list) list of strings
371
372 Sets a list of strings in $key inside $group_name. The strings will be
373 escaped if contain special characters. If $key cannot be found then it
374 is created. If $group_name cannot be found then it is created.
375
376 $key_file->set_string ($group_name, $key, $value)
377 · $group_name (string)
378
379 · $key (string)
380
381 · $value (string)
382
383 Sets a string value to $key inside $group_name. The string will be
384 escaped if it contains special characters. If $key is not found, it is
385 created.
386
387 string = $key_file->to_data
388 Returns the key file as a string.
389
390 May croak with a Glib::Error in $@ on failure.
391
392 string = $key_file->get_value ($group_name, $key)
393 · $group_name (string)
394
395 · $key (string)
396
397 Retrieves the literal value of $key inside $group_name.
398
399 May croak with a Glib::Error in $@ on failure.
400
401 $key_file->set_value ($group_name, $key, $value)
402 · $group_name (string)
403
404 · $key (string)
405
406 · $value (string)
407
408 Sets the literal value of $key inside $group_name. If $key cannot be
409 found, it is created. If $group_name cannot be found, it is created.
410
412 flags Glib::KeyFileFlags
413 · 'none' / 'G_KEY_FILE_NONE'
414
415 · 'keep-comments' / 'G_KEY_FILE_KEEP_COMMENTS'
416
417 · 'keep-translations' / 'G_KEY_FILE_KEEP_TRANSLATIONS'
418
420 Glib
421
423 Copyright (C) 2003-2011 by the gtk2-perl team.
424
425 This software is licensed under the LGPL. See Glib for a full notice.
426
427
428
429perl v5.32.0 2020-07-28 Glib::KeyFile(3)