Movatterモバイル変換


[0]ホーム

URL:


functions /tie
(source,CPAN)
You are viewing the version of this documentation from Perl 5.34.3.View the latest version
#tie VARIABLE,CLASSNAME,LIST

This function binds a variable to a package class that will provide the implementation for the variable. VARIABLE is the name of the variable to be enchanted. CLASSNAME is the name of a class implementing objects of correct type. Any additional arguments are passed to the appropriate constructor method of the class (meaningTIESCALAR,TIEHANDLE,TIEARRAY, orTIEHASH). Typically these are arguments such as might be passed to thedbm_open(3) function of C. The object returned by the constructor is also returned by thetie function, which would be useful if you want to access other methods in CLASSNAME.

Note that functions such askeys andvalues may return huge lists when used on large objects, like DBM files. You may prefer to use theeach function to iterate over such. Example:

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

A class implementing a hash should have the following methods:

TIEHASH classname, LISTFETCH this, keySTORE this, key, valueDELETE this, keyCLEAR thisEXISTS this, keyFIRSTKEY thisNEXTKEY this, lastkeySCALAR thisDESTROY thisUNTIE this

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

TIEARRAY classname, LISTFETCH this, keySTORE this, key, valueFETCHSIZE thisSTORESIZE this, countCLEAR thisPUSH this, LISTPOP thisSHIFT thisUNSHIFT this, LISTSPLICE this, offset, length, LISTEXTEND this, countDELETE this, keyEXISTS this, keyDESTROY thisUNTIE this

A class implementing a filehandle should have the following methods:

TIEHANDLE classname, LISTREAD this, scalar, length, offsetREADLINE thisGETC thisWRITE this, scalar, length, offsetPRINT this, LISTPRINTF this, format, LISTBINMODE thisEOF thisFILENO thisSEEK this, position, whenceTELL thisOPEN this, mode, LISTCLOSE thisDESTROY thisUNTIE this

A class implementing a scalar should have the following methods:

TIESCALAR classname, LISTFETCH this,STORE this, valueDESTROY thisUNTIE this

Not all methods indicated above need be implemented. Seeperltie,Tie::Hash,Tie::Array,Tie::Scalar, andTie::Handle.

Unlikedbmopen, thetie function will notuse orrequire a module for you; you need to do that explicitly yourself. SeeDB_File or theConfig module for interestingtie implementations.

For further details seeperltie,tied.

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp