<?xml version="1.0" encoding="windows-1252"?>
<node id="1264" title="perlman:Tie::Array" created="1999-12-22 19:53:36" updated="2005-08-14 16:44:36">
<type id="119">
perlfunc</type>
<author id="113">
root</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
Tie::Array - base class for tied arrays

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
&lt;PRE&gt;    package NewArray;
    use Tie::Array;
    @ISA = ('Tie::Array');
                       
    # mandatory methods
    sub TIEARRAY { ... }  
    sub FETCH { ... }     
    sub FETCHSIZE { ... } 
        
    sub STORE { ... }        # mandato</field>
<field name="description">

&lt;P&gt;
This module provides methods for array-tying classes. See
[perlman:perltie|perltie] for a list of the functions required in order to tie an array to a package.
The basic &lt;STRONG&gt;Tie::Array&lt;/STRONG&gt; package provides stub &lt;CODE&gt;DELETE&lt;/CODE&gt; 
and [perlman:perlguts|perlguts] methods, and implementations of &lt;CODE&gt;PUSH&lt;/CODE&gt;, &lt;CODE&gt;POP&lt;/CODE&gt;, &lt;CODE&gt;SHIFT&lt;/CODE&gt;, 
&lt;CODE&gt;UNSHIFT&lt;/CODE&gt;, &lt;CODE&gt;SPLICE&lt;/CODE&gt; and &lt;CODE&gt;CLEAR&lt;/CODE&gt; in terms of basic &lt;CODE&gt;FETCH&lt;/CODE&gt;, &lt;CODE&gt;STORE&lt;/CODE&gt;, 
&lt;CODE&gt;FETCHSIZE&lt;/CODE&gt;, &lt;CODE&gt;STORESIZE&lt;/CODE&gt;.

&lt;P&gt;
The &lt;STRONG&gt;Tie::StdArray&lt;/STRONG&gt; package provides efficient methods required for tied arrays which are
implemented as blessed references to an ``inner'' perl array. It inherits
from &lt;STRONG&gt;Tie::Array&lt;/STRONG&gt;, and should cause tied arrays to behave exactly like standard arrays,
allowing for selective overloading of methods. 

&lt;P&gt;
For developers wishing to write their own tied arrays, the required methods
are briefly defined below. See the [perlman:perltie|perltie] section for more detailed descriptive, as well as example code:

&lt;DL&gt;
&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_TIEARRAY"&gt;TIEARRAY classname, LIST&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
The class method is invoked by the command &lt;CODE&gt;tie @array, classname&lt;/CODE&gt;. Associates an array instance with the specified class. &lt;CODE&gt;LIST&lt;/CODE&gt; would represent additional arguments (along the lines of [perlman:lib:AnyDBM_File|AnyDBM_File] and compatriots) needed to complete the association. The method should
return an object of a class which provides the methods below. 

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_STORE"&gt;STORE this, index, value&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Store datum &lt;EM&gt;value&lt;/EM&gt; into &lt;EM&gt;index&lt;/EM&gt; for the tied array assoicated with object &lt;EM&gt;this&lt;/EM&gt;. If this makes the array larger then class's mapping of [perlfunc:undef|undef] should be returned for new positions.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_FETCH"&gt;FETCH this, index&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Retrieve the datum in &lt;EM&gt;index&lt;/EM&gt; for the tied array assoicated with object &lt;EM&gt;this&lt;/EM&gt;.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_FETCHSIZE"&gt;FETCHSIZE this&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Returns the total number of items in the tied array assoicated with object &lt;EM&gt;this&lt;/EM&gt;. (Equivalent to [perlfunc:scalar|scalar]).

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_STORESIZE"&gt;STORESIZE this, count&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Sets the total number of items in the tied array assoicated with object &lt;EM&gt;this&lt;/EM&gt; to be &lt;EM&gt;count&lt;/EM&gt;. If this makes the array larger then class's mapping of [perlfunc:undef|undef] should be returned for new positions. If the array becomes smaller then
entries beyond count should be deleted. 

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_EXTEND"&gt;EXTEND this, count&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Informative call that array is likely to grow to have &lt;EM&gt;count&lt;/EM&gt; entries. Can be used to optimize allocation. This method need do nothing.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_CLEAR"&gt;CLEAR this&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Clear (remove, delete, ...) all values from the tied array assoicated with
object &lt;EM&gt;this&lt;/EM&gt;.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_DESTROY"&gt;DESTROY this&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Normal object destructor method.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PUSH"&gt;PUSH this, LIST&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Append elements of 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; to the array.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_POP"&gt;POP this&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Remove last element of the array and return it.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_SHIFT"&gt;SHIFT this&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Remove the first element of the array (shifting other elements down) and
return it.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_UNSHIFT"&gt;UNSHIFT this, LIST&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Insert 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; elements at the begining of the array, moving
existing elements up to make room.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_SPLICE"&gt;SPLICE this, offset, length, LIST&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Perform the equivalent of [perlfunc:splice|splice] on the array. 

&lt;P&gt;
&lt;EM&gt;offset&lt;/EM&gt; is optional and defaults to zero, negative values count back from the end
of the array. 

&lt;P&gt;
&lt;EM&gt;length&lt;/EM&gt; is optional and defaults to rest of the array.

&lt;P&gt;
&lt;EM&gt;LIST&lt;/EM&gt; may be empty.

&lt;P&gt;
Returns a list of the original &lt;EM&gt;length&lt;/EM&gt; elements at &lt;EM&gt;offset&lt;/EM&gt;.

&lt;/DL&gt;
&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="CAVEATS"&gt;CAVEATS&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
There is no support at present for tied 
&lt;FONT SIZE=-1&gt;@ISA.&lt;/FONT&gt; There is a potential conflict between magic entries needed to notice setting of 
&lt;FONT SIZE=-1&gt;@ISA,&lt;/FONT&gt; and those needed to implement 'tie'.
   

&lt;P&gt;
Very little consideration has been given to the behaviour of tied arrays
when &lt;CODE&gt;$&amp;#091;&lt;/CODE&gt; is not default value of zero.

&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="AUTHOR"&gt;AUTHOR&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
Nick Ing-Simmons &lt;A
HREF="mailto:&amp;lt;nik@tiuk.ti.com&amp;gt;"&gt;&amp;lt;nik@tiuk.ti.com&amp;gt;&lt;/A&gt;

&lt;HR&gt;
</field>
</data>
</node>
