tie 
tieVARIABLE,CLASSNAME,LIST
This function binds a variable to a package class that will
provide the implementation for the variable.
VARIABLE is the variable (scalar, array, or
hash) or typeglob (representing a filehandle) to be tied.
CLASSNAME is the name of a class implementing
objects of an appropriate type.
Any additional arguments are passed to the appropriate constructor
method of the class, meaning one of TIESCALAR, TIEARRAY, TIEHASH, or TIEHANDLE. (If the appropriate method is not
found, an exception is raised.) Typically, these are arguments such as
might be passed to the dbm_open(3) function of C,
but their meaning is package dependent. The object returned by the
constructor is in turn returned by the tie function, which can be useful if you want
to access other methods in CLASSNAME. (The
object can also be accessed through the tied function.) So a class for tying a hash to
an I SAM implementation might provide an extra method to traverse a set
of keys sequentially (the “S” of I SAM), since your typical DBM
implementation can’t do that.
Functions such as keys and
values may return huge list values
when used on large objects like DBM files. You may prefer to use the
each function to iterate over such.
For example:
use NDBM_File; tie(%ALIASES, "NDBM_File", "/etc/aliases", 1, 0) || die "Can't open aliases: $!"; while (($key,$val) = each %ALIASES) { say "$key = $val"; } untie ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access