TIE

tie VARIABLE,PACKAGENAME,LIST

This function binds a variable to a package that will provide the implementation for the variable. VARIABLE is the name of the variable to be enchanted. PACKAGENAME is the name of a package implementing objects of correct type. Any additional arguments are passed to the "new" method of the package (meaning TIESCALAR, TIEARRAY, or TIEHASH). Typically these are arguments such as might be passed to the dbm_open() function of C.

Note that functions such as keys() and values() may return huge array values when used on large objects, like DBM files. You may prefer to use the each() function to iterate over such. Example:

# print out history file offsets tie(%HIST, NDBM_File, '/usr/lib/news/history', 1, 0); while (($key,$val) = each %HIST) { print $key, ' = ', unpack('L',$val), "\n"; } untie(%HIST);

A package implementing an associative array should have the following methods:

TIEHASH objectname, LIST DESTROY this FETCH this, key STORE this, key, value DELETE this, key EXISTS this, key FIRSTKEY this NEXTKEY this, lastkey

A package implementing an ordinary array should have the following methods:

TIEARRAY objectname, LIST DESTROY this FETCH this, key STORE this, key, value [others TBD]

A package implementing a scalar should have the following methods:

TIESCALAR objectname, LIST DESTROY this FETCH this, STORE this, value

Back to functions