Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "Tie::IxHash 3" | |
132 | .TH Tie::IxHash 3 "1997-11-20" "perl v5.8.0" "User Contributed Perl Documentation" | |
133 | .SH "NAME" | |
134 | Tie::IxHash \- ordered associative arrays for Perl | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 3 | |
138 | \& # simple usage | |
139 | \& use Tie::IxHash; | |
140 | \& tie HASHVARIABLE, Tie::IxHash [, LIST]; | |
141 | .Ve | |
142 | .PP | |
143 | .Vb 17 | |
144 | \& # OO interface with more powerful features | |
145 | \& use Tie::IxHash; | |
146 | \& TIEOBJECT = Tie::IxHash->new( [LIST] ); | |
147 | \& TIEOBJECT->Splice( OFFSET [, LENGTH [, LIST]] ); | |
148 | \& TIEOBJECT->Push( LIST ); | |
149 | \& TIEOBJECT->Pop; | |
150 | \& TIEOBJECT->Shift; | |
151 | \& TIEOBJECT->Unshift( LIST ); | |
152 | \& TIEOBJECT->Keys( [LIST] ); | |
153 | \& TIEOBJECT->Values( [LIST] ); | |
154 | \& TIEOBJECT->Indices( LIST ); | |
155 | \& TIEOBJECT->Delete( [LIST] ); | |
156 | \& TIEOBJECT->Replace( OFFSET, VALUE, [KEY] ); | |
157 | \& TIEOBJECT->Reorder( LIST ); | |
158 | \& TIEOBJECT->SortByKey; | |
159 | \& TIEOBJECT->SortByValue; | |
160 | \& TIEOBJECT->Length; | |
161 | .Ve | |
162 | .SH "DESCRIPTION" | |
163 | .IX Header "DESCRIPTION" | |
164 | This Perl module implements Perl hashes that preserve the order in which the | |
165 | hash elements were added. The order is not affected when values | |
166 | corresponding to existing keys in the IxHash are changed. The elements can | |
167 | also be set to any arbitrary supplied order. The familiar perl array | |
168 | operations can also be performed on the IxHash. | |
169 | .ie n .Sh "Standard ""TIEHASH"" Interface" | |
170 | .el .Sh "Standard \f(CWTIEHASH\fP Interface" | |
171 | .IX Subsection "Standard TIEHASH Interface" | |
172 | The standard \f(CW\*(C`TIEHASH\*(C'\fR mechanism is available. This interface is | |
173 | recommended for simple uses, since the usage is exactly the same as | |
174 | regular Perl hashes after the \f(CW\*(C`tie\*(C'\fR is declared. | |
175 | .Sh "Object Interface" | |
176 | .IX Subsection "Object Interface" | |
177 | This module also provides an extended object-oriented interface that can be | |
178 | used for more powerful operations with the IxHash. The following methods | |
179 | are available: | |
180 | .IP "\s-1FETCH\s0, \s-1STORE\s0, \s-1DELETE\s0, \s-1EXISTS\s0" 8 | |
181 | .IX Item "FETCH, STORE, DELETE, EXISTS" | |
182 | These standard \f(CW\*(C`TIEHASH\*(C'\fR methods mandated by Perl can be used directly. | |
183 | See the \f(CW\*(C`tie\*(C'\fR entry in \fIperlfunc\fR\|(1) for details. | |
184 | .IP "Push, Pop, Shift, Unshift, Splice" 8 | |
185 | .IX Item "Push, Pop, Shift, Unshift, Splice" | |
186 | These additional methods resembling Perl functions are available for | |
187 | operating on key-value pairs in the IxHash. The behavior is the same as the | |
188 | corresponding perl functions, except when a supplied hash key already exists | |
189 | in the hash. In that case, the existing value is updated but its order is | |
190 | not affected. To unconditionally alter the order of a supplied key-value | |
191 | pair, first \f(CW\*(C`DELETE\*(C'\fR the IxHash element. | |
192 | .IP "Keys" 8 | |
193 | .IX Item "Keys" | |
194 | Returns an array of IxHash element keys corresponding to the list of supplied | |
195 | indices. Returns an array of all the keys if called without arguments. | |
196 | Note the return value is mostly only useful when used in a list context | |
197 | (since perl will convert it to the number of elements in the array when | |
198 | used in a scalar context, and that may not be very useful). | |
199 | .Sp | |
200 | If a single argument is given, returns the single key corresponding to | |
201 | the index. This is usable in either scalar or list context. | |
202 | .IP "Values" 8 | |
203 | .IX Item "Values" | |
204 | Returns an array of IxHash element values corresponding to the list of supplied | |
205 | indices. Returns an array of all the values if called without arguments. | |
206 | Note the return value is mostly only useful when used in a list context | |
207 | (since perl will convert it to the number of elements in the array when | |
208 | used in a scalar context, and that may not be very useful). | |
209 | .Sp | |
210 | If a single argument is given, returns the single value corresponding to | |
211 | the index. This is usable in either scalar or list context. | |
212 | .IP "Indices" 8 | |
213 | .IX Item "Indices" | |
214 | Returns an array of indices corresponding to the supplied list of keys. | |
215 | Note the return value is mostly only useful when used in a list context | |
216 | (since perl will convert it to the number of elements in the array when | |
217 | used in a scalar context, and that may not be very useful). | |
218 | .Sp | |
219 | If a single argument is given, returns the single index corresponding to | |
220 | the key. This is usable in either scalar or list context. | |
221 | .IP "Delete" 8 | |
222 | .IX Item "Delete" | |
223 | Removes elements with the supplied keys from the IxHash. | |
224 | .IP "Replace" 8 | |
225 | .IX Item "Replace" | |
226 | Substitutes the IxHash element at the specified index with the supplied | |
227 | value-key pair. If a key is not supplied, simply substitutes the value at | |
228 | index with the supplied value. If an element with the supplied key already | |
229 | exists, it will be removed from the IxHash first. | |
230 | .IP "Reorder" 8 | |
231 | .IX Item "Reorder" | |
232 | This method can be used to manipulate the internal order of the IxHash | |
233 | elements by supplying a list of keys in the desired order. Note however, | |
234 | that any IxHash elements whose keys are not in the list will be removed from | |
235 | the IxHash. | |
236 | .IP "Length" 8 | |
237 | .IX Item "Length" | |
238 | Returns the number of IxHash elements. | |
239 | .IP "SortByKey" 8 | |
240 | .IX Item "SortByKey" | |
241 | Reorders the IxHash elements by textual comparison of the keys. | |
242 | .IP "SortByValue" 8 | |
243 | .IX Item "SortByValue" | |
244 | Reorders the IxHash elements by textual comparison of the values. | |
245 | .SH "EXAMPLE" | |
246 | .IX Header "EXAMPLE" | |
247 | .Vb 1 | |
248 | \& use Tie::IxHash; | |
249 | .Ve | |
250 | .PP | |
251 | .Vb 7 | |
252 | \& # simple interface | |
253 | \& $t = tie(%myhash, Tie::IxHash, 'a' => 1, 'b' => 2); | |
254 | \& %myhash = (first => 1, second => 2, third => 3); | |
255 | \& $myhash{fourth} = 4; | |
256 | \& @keys = keys %myhash; | |
257 | \& @values = values %myhash; | |
258 | \& print("y") if exists $myhash{third}; | |
259 | .Ve | |
260 | .PP | |
261 | .Vb 7 | |
262 | \& # OO interface | |
263 | \& $t = Tie::IxHash->new(first => 1, second => 2, third => 3); | |
264 | \& $t->Push(fourth => 4); # same as $myhash{'fourth'} = 4; | |
265 | \& ($k, $v) = $t->Pop; # $k is 'fourth', $v is 4 | |
266 | \& $t->Unshift(neg => -1, zeroth => 0); | |
267 | \& ($k, $v) = $t->Shift; # $k is 'neg', $v is -1 | |
268 | \& @oneandtwo = $t->Splice(1, 2, foo => 100, bar => 101); | |
269 | .Ve | |
270 | .PP | |
271 | .Vb 8 | |
272 | \& @keys = $t->Keys; | |
273 | \& @values = $t->Values; | |
274 | \& @indices = $t->Indices('foo', 'zeroth'); | |
275 | \& @itemkeys = $t->Keys(@indices); | |
276 | \& @itemvals = $t->Values(@indices); | |
277 | \& $t->Replace(2, 0.3, 'other'); | |
278 | \& $t->Delete('second', 'zeroth'); | |
279 | \& $len = $t->Length; # number of key-value pairs | |
280 | .Ve | |
281 | .PP | |
282 | .Vb 3 | |
283 | \& $t->Reorder(reverse @keys); | |
284 | \& $t->SortByKey; | |
285 | \& $t->SortByValue; | |
286 | .Ve | |
287 | .SH "BUGS" | |
288 | .IX Header "BUGS" | |
289 | You cannot specify a negative length to \f(CW\*(C`Splice\*(C'\fR. Negative indexes are \s-1OK\s0, | |
290 | though. | |
291 | .PP | |
292 | Indexing always begins at 0 (despite the current \f(CW$[\fR setting) for | |
293 | all the functions. | |
294 | .SH "TODO" | |
295 | .IX Header "TODO" | |
296 | Addition of elements with keys that already exist to the end of the IxHash | |
297 | must be controlled by a switch. | |
298 | .PP | |
299 | Provide \f(CW\*(C`TIEARRAY\*(C'\fR interface when it stabilizes in Perl. | |
300 | .PP | |
301 | Rewrite using XSUBs for efficiency. | |
302 | .SH "AUTHOR" | |
303 | .IX Header "AUTHOR" | |
304 | Gurusamy Sarathy gsar@umich.edu | |
305 | .PP | |
306 | Copyright (c) 1995 Gurusamy Sarathy. All rights reserved. | |
307 | This program is free software; you can redistribute it and/or | |
308 | modify it under the same terms as Perl itself. | |
309 | .SH "VERSION" | |
310 | .IX Header "VERSION" | |
311 | Version 1.21 20 Nov 1997 | |
312 | .SH "SEE ALSO" | |
313 | .IX Header "SEE ALSO" | |
314 | \&\fIperl\fR\|(1) |