home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Book HomeJava and XSLTSearch this book

8.215. Tie::Array, Tie::StdArray

Provides methods for array-tying classes. (See the perltie manpage for the functions needed for tying an array to a package.) The basic Tie::Array package provides stub DELETE and EXTEND methods and implements PUSH, POP, SHIFT, UNSHIFT, SPLICE, and CLEAR in terms of basic FETCH, STORE, FETCHSIZE, and STORESIZE.

Tie::StdArray inherits from Tie::Array and provides the methods needed for tied arrays implemented as blessed references to an "inner" Perl array. It causes tied arrays to behave like standard arrays, allowing for selective method overloading.

See the perltie manpage for more detailed information and for examples. To write your own tied arrays, use the following required methods.

TIEARRAY

TIEARRAY classname, list

Constructor. This method is invoked by the command tie @array , classname. Associates an array instance with the specified class. list represents additional arguments needed to complete the association. Should return an object of a class that provides the remaining methods.

CLEAR

CLEAR this

Clears all values from the tied array associated with object this.

DESTROY

DESTROY this

Normal object destructor.

EXTEND

EXTEND this, count

Doesn't need to do anything. Provides information that the array will likely grow to have count entries.

FETCH

FETCH this, index

Retrieves the data item in index for the tied array associated with object this.

FETCHSIZE

FETCHSIZE this

Returns the number of items in the tied array associated with object this.

POP

POP this

Removes the last element from the array and returns it.

PUSH

PUSH this, list

Appends elements of list to the array.

SHIFT

SHIFT this

Removes and returns the first element of the array, shifting the remaining elements down.

SPLICE

SPLICE this, offset, length, list

Performs the equivalent of a splice on the array. Returns a list of the original length elements at the specified offset. The arguments are:

offset
Optional. Defaults to 0; if negative, counts back from the end of the array.

length
Optional. Defaults to the rest of the array.

list
May be empty.

STORE

STORE this, index, value

Stores value of a data item into index for the tied array associated with object this. If the resulting array is larger than the class's mapping for the array, undef should be returned for new positions.

STORESIZE

STORESIZE this, count

Sets the total number of items in the tied array associated with object this to count. If this makes the array larger than the class's mapping for the array, then undef should be returned for new positions. If it makes the array smaller than the mapping, then entries beyond count should be deleted.

UNSHIFT

UNSHIFT this, list

Inserts list elements at the beginning of the array, moving existing elements up to make room.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.











??????????????@Mail.ru