home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Tie::IxHash - ordered associative arrays for Perl</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Tie::IxHash - ordered associative arrays for Perl</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <UL>
-
- <LI><A HREF="#standard tiehash interface">Standard <CODE>TIEHASH</CODE> Interface</A></LI>
- <LI><A HREF="#object interface">Object Interface</A></LI>
- </UL>
-
- <LI><A HREF="#example">EXAMPLE</A></LI>
- <LI><A HREF="#bugs">BUGS</A></LI>
- <LI><A HREF="#todo">TODO</A></LI>
- <LI><A HREF="#author">AUTHOR</A></LI>
- <LI><A HREF="#version">VERSION</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Tie::IxHash - ordered associative arrays for Perl</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- # simple usage
- use Tie::IxHash;
- tie HASHVARIABLE, Tie::IxHash [, LIST];
- </PRE>
- <PRE>
-
- # OO interface with more powerful features
- use Tie::IxHash;
- TIEOBJECT = Tie::IxHash->new( [LIST] );
- TIEOBJECT->Splice( OFFSET [, LENGTH [, LIST]] );
- TIEOBJECT->Push( LIST );
- TIEOBJECT->Pop;
- TIEOBJECT->Shift;
- TIEOBJECT->Unshift( LIST );
- TIEOBJECT->Keys( [LIST] );
- TIEOBJECT->Values( [LIST] );
- TIEOBJECT->Indices( LIST );
- TIEOBJECT->Delete( [LIST] );
- TIEOBJECT->Replace( OFFSET, VALUE, [KEY] );
- TIEOBJECT->Reorder( LIST );
- TIEOBJECT->SortByKey;
- TIEOBJECT->SortByValue;
- TIEOBJECT->Length;</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>This Perl module implements Perl hashes that preserve the order in which the
- hash elements were added. The order is not affected when values
- corresponding to existing keys in the IxHash are changed. The elements can
- also be set to any arbitrary supplied order. The familiar perl array
- operations can also be performed on the IxHash.</P>
- <P>
- <H2><A NAME="standard tiehash interface">Standard <CODE>TIEHASH</CODE> Interface</A></H2>
- <P>The standard <CODE>TIEHASH</CODE> mechanism is available. This interface is
- recommended for simple uses, since the usage is exactly the same as
- regular Perl hashes after the <A HREF="../../../lib/Pod/perlfunc.html#item_tie"><CODE>tie</CODE></A> is declared.</P>
- <P>
- <H2><A NAME="object interface">Object Interface</A></H2>
- <P>This module also provides an extended object-oriented interface that can be
- used for more powerful operations with the IxHash. The following methods
- are available:</P>
- <DL>
- <DT><STRONG><A NAME="item_FETCH%2C_STORE%2C_DELETE%2C_EXISTS">FETCH, STORE, DELETE, EXISTS</A></STRONG><BR>
- <DD>
- These standard <CODE>TIEHASH</CODE> methods mandated by Perl can be used directly.
- See the <A HREF="../../../lib/Pod/perlfunc.html#item_tie"><CODE>tie</CODE></A> entry in <CODE>perlfunc(1)</CODE> for details.
- <P></P>
- <DT><STRONG><A NAME="item_Push%2C_Pop%2C_Shift%2C_Unshift%2C_Splice">Push, Pop, Shift, Unshift, Splice</A></STRONG><BR>
- <DD>
- These additional methods resembling Perl functions are available for
- operating on key-value pairs in the IxHash. The behavior is the same as the
- corresponding perl functions, except when a supplied hash key already exists
- in the hash. In that case, the existing value is updated but its order is
- not affected. To unconditionally alter the order of a supplied key-value
- pair, first <CODE>DELETE</CODE> the IxHash element.
- <P></P>
- <DT><STRONG><A NAME="item_Keys">Keys</A></STRONG><BR>
- <DD>
- Returns an array of IxHash element keys corresponding to the list of supplied
- indices. Returns an array of all the keys if called without arguments.
- Note the return value is mostly only useful when used in a list context
- (since perl will convert it to the number of elements in the array when
- used in a scalar context, and that may not be very useful).
- <P>If a single argument is given, returns the single key corresponding to
- the index. This is usable in either scalar or list context.</P>
- <P></P>
- <DT><STRONG><A NAME="item_Values">Values</A></STRONG><BR>
- <DD>
- Returns an array of IxHash element values corresponding to the list of supplied
- indices. Returns an array of all the values if called without arguments.
- Note the return value is mostly only useful when used in a list context
- (since perl will convert it to the number of elements in the array when
- used in a scalar context, and that may not be very useful).
- <P>If a single argument is given, returns the single value corresponding to
- the index. This is usable in either scalar or list context.</P>
- <P></P>
- <DT><STRONG><A NAME="item_Indices">Indices</A></STRONG><BR>
- <DD>
- Returns an array of indices corresponding to the supplied list of keys.
- Note the return value is mostly only useful when used in a list context
- (since perl will convert it to the number of elements in the array when
- used in a scalar context, and that may not be very useful).
- <P>If a single argument is given, returns the single index corresponding to
- the key. This is usable in either scalar or list context.</P>
- <P></P>
- <DT><STRONG><A NAME="item_Delete">Delete</A></STRONG><BR>
- <DD>
- Removes elements with the supplied keys from the IxHash.
- <P></P>
- <DT><STRONG><A NAME="item_Replace">Replace</A></STRONG><BR>
- <DD>
- Substitutes the IxHash element at the specified index with the supplied
- value-key pair. If a key is not supplied, simply substitutes the value at
- index with the supplied value. If an element with the supplied key already
- exists, it will be removed from the IxHash first.
- <P></P>
- <DT><STRONG><A NAME="item_Reorder">Reorder</A></STRONG><BR>
- <DD>
- This method can be used to manipulate the internal order of the IxHash
- elements by supplying a list of keys in the desired order. Note however,
- that any IxHash elements whose keys are not in the list will be removed from
- the IxHash.
- <P></P>
- <DT><STRONG><A NAME="item_Length">Length</A></STRONG><BR>
- <DD>
- Returns the number of IxHash elements.
- <P></P>
- <DT><STRONG><A NAME="item_SortByKey">SortByKey</A></STRONG><BR>
- <DD>
- Reorders the IxHash elements by textual comparison of the keys.
- <P></P>
- <DT><STRONG><A NAME="item_SortByValue">SortByValue</A></STRONG><BR>
- <DD>
- Reorders the IxHash elements by textual comparison of the values.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="example">EXAMPLE</A></H1>
- <PRE>
- use Tie::IxHash;</PRE>
- <PRE>
- # simple interface
- $t = tie(%myhash, Tie::IxHash, 'a' => 1, 'b' => 2);
- %myhash = (first => 1, second => 2, third => 3);
- $myhash{fourth} = 4;
- @keys = keys %myhash;
- @values = values %myhash;
- print("y") if exists $myhash{third};
- </PRE>
- <PRE>
-
- # OO interface
- $t = Tie::IxHash->new(first => 1, second => 2, third => 3);
- $t->Push(fourth => 4); # same as $myhash{'fourth'} = 4;
- ($k, $v) = $t->Pop; # $k is 'fourth', $v is 4
- $t->Unshift(neg => -1, zeroth => 0);
- ($k, $v) = $t->Shift; # $k is 'neg', $v is -1
- @oneandtwo = $t->Splice(1, 2, foo => 100, bar => 101);</PRE>
- <PRE>
-
- @keys = $t->Keys;
- @values = $t->Values;
- @indices = $t->Indices('foo', 'zeroth');
- @itemkeys = $t->Keys(@indices);
- @itemvals = $t->Values(@indices);
- $t->Replace(2, 0.3, 'other');
- $t->Delete('second', 'zeroth');
- $len = $t->Length; # number of key-value pairs</PRE>
- <PRE>
- $t->Reorder(reverse @keys);
- $t->SortByKey;
- $t->SortByValue;</PRE>
- <P>
- <HR>
- <H1><A NAME="bugs">BUGS</A></H1>
- <P>You cannot specify a negative length to <CODE>Splice</CODE>. Negative indexes are OK,
- though.</P>
- <P>Indexing always begins at 0 (despite the current <CODE>$[</CODE> setting) for
- all the functions.</P>
- <P>
- <HR>
- <H1><A NAME="todo">TODO</A></H1>
- <P>Addition of elements with keys that already exist to the end of the IxHash
- must be controlled by a switch.</P>
- <P>Provide <CODE>TIEARRAY</CODE> interface when it stabilizes in Perl.</P>
- <P>Rewrite using XSUBs for efficiency.</P>
- <P>
- <HR>
- <H1><A NAME="author">AUTHOR</A></H1>
- <P>Gurusamy Sarathy <A HREF="mailto:gsar@umich.edu">gsar@umich.edu</A></P>
- <P>Copyright (c) 1995 Gurusamy Sarathy. All rights reserved.
- This program is free software; you can redistribute it and/or
- modify it under the same terms as Perl itself.</P>
- <P>
- <HR>
- <H1><A NAME="version">VERSION</A></H1>
- <P>Version 1.21 20 Nov 1997</P>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><CODE>perl(1)</CODE></P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Tie::IxHash - ordered associative arrays for Perl</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-