1IniHash(3) User Contributed Perl Documentation IniHash(3)
2
3
4
6 Config::IniHash - Perl extension for reading and writing INI files
7
8 version 2.9.0
9
11 use Config::IniHash;
12 $Config = ReadINI 'c:\some\file.ini';
13
15 This module reads and writes INI files.
16
17 Functions
18
19 ReadINI
20
21 $hashreference = ReadINI ($filename, %options)
22 $hashreference = ReadINI (\$data, %options)
23 $hashreference = ReadINI (\@data, %options)
24 $hashreference = ReadINI ($filehandle, %options)
25
26 The returned hash contains a reference to a hash for each section of
27 the INI.
28
29 [section]
30 name=value
31 leads to
32 $hash->{section}->{name} = value;
33
34 The available options are:
35
36 heredoc
37 - controls whether the module supports the heredoc syntax :
38
39 name=<<END
40 the
41 many lines
42 long value
43 END
44 othername=value
45
46 Default: 0 = OFF
47
48 systemvars
49 - controls whether the (system) variables enclosed in %% are inter‐
50 polated and optionaly contains the values in a hash ref.
51
52 name=%USERNAME%
53 leads to
54 $data->{section}->{name} = "Jenda"
55
56 systemvars = 1 - yes, take values from %ENV
57 systemvars = \%hash - yes, take values from %hash
58 systemvars = 0 - no
59
60 case
61 - controls whether the created hash is case insensitive. The possi‐
62 ble values are
63
64 sensitive - the hash will be case sensitive
65 tolower - the hash will be case sensitive, all keys are made lowercase
66 toupper - the hash will be case sensitive, all keys are made uppercase
67 preserve - the hash will be case insensitive, the case is preserved
68 lower - the hash will be case insensitive, all keys are made lowercase
69 upper - the hash will be case insensitive, all keys are made uppercase
70
71 withdefaults
72 - controls whether the created section hashes support defaults.
73
74 sectionorder
75 - if set to a true value then created hash will contain
76
77 $config->{'__SECTIONS__'} = [ 'the', 'names', 'of', 'the', 'sections', 'in', 'the',
78 'order', 'they', 'were', 'specified', 'in', 'the', 'INI file'];
79
80 allow_multiple
81 - if set to a true scalar value then multiple items with the same
82 names in a section do not overwrite each other, but result in an
83 array of the values.
84
85 - if set to a hash of hashes (or hash of arrays or hash of comma
86 separated item names) specifies what items in what sections will
87 end up as hashes containing the list of values. All the specified
88 items will be arrays, even if there is just a single value. To
89 affect the items in all sections use section name '*'.
90
91 By default false.
92
93 forValue
94 - allows you to install a callback that will be called for each
95 value as soon as it is read but before it is stored in the hash.
96 The function is called like this:
97
98 $value = $forValue->($name, $value, $sectionname, $INIhashref);
99
100 If the callback returns an undef, the value will not be stored.
101
102 comment
103 - regular expression used to identify comments or a string contain‐
104 ing the list of characters starting a comment. Each line is tested
105 against the regexp is ignored if matches. If you specify a string a
106 regexp like this will be created:
107
108 qr/^\s*[the_list]/
109
110 The default is
111
112 qr/^\s*[#;]
113
114 You may also set the defaults for the options by modifying the $Con‐
115 fig::IniHash::optionname variables. These default settings will be used
116 if you do not specify the option in the ReadINI() or ReadSection()
117 call.
118
119 ReadSection
120
121 $hashreference = ReadSection ($string)
122
123 This function parses a string as if it was a section of an INI file and
124 creates a hash with the values. It accepts the same options as Rea‐
125 dINI.
126
127 WriteINI
128
129 WriteINI ($filename, $hashreference)
130
131 Writes the hash of hashes to a file.
132
133 PrintINI
134
135 The same as WriteINI().
136
138 Jan Krynicky <Jenda@Krynicky.cz> http://Jenda.Krynicky.cz
139
141 Copyright (c) 2002-2005 Jan Krynicky <Jenda@Krynicky.cz>. All rights
142 reserved.
143
144 This program is free software; you can redistribute it and/or modify it
145 under the same terms as Perl itself.
146
147
148
149perl v5.8.8 2007-03-19 IniHash(3)