home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / perlman / man / perltie.txt < prev    next >
Encoding:
Text File  |  1999-09-09  |  25.1 KB  |  651 lines

  1. NAME
  2.        perltie - how to hide an object class in a simple variable
  3.  
  4. SYNOPSIS
  5.         tie VARIABLE, CLASSNAME, LIST
  6.  
  7.         $object = tied VARIABLE
  8.  
  9.         untie VARIABLE
  10.  
  11. DESCRIPTION
  12.        Prior to release 5.0 of Perl, a programmer could use
  13.        dbmopen() to magically connect an on-disk database in the
  14.        standard Unix dbm(3x) format to a %HASH in their program.
  15.        However, their Perl was either built with one particular
  16.        dbm library or another, but not both, and you couldn't
  17.        extend this mechanism to other packages or types of
  18.        variables.
  19.  
  20.        Now you can.
  21.  
  22.        The tie() function binds a variable to a class (package)
  23.        that will provide the implementation for access methods
  24.        for that variable.  Once this magic has been performed,
  25.        accessing a tied variable automatically triggers method
  26.        calls in the proper class.  All of the complexity of the
  27.        class is hidden behind magic methods calls.  The method
  28.        names are in ALL CAPS, which is a convention that Perl
  29.        uses to indicate that they're called implicitly rather
  30.        than explicitly--just like the BEGIN() and END()
  31.        functions.
  32.  
  33.        In the tie() call, VARIABLE is the name of the variable to
  34.        be enchanted.  CLASSNAME is the name of a class
  35.        implementing objects of the correct type.  Any additional
  36.        arguments in the LIST are passed to the appropriate
  37.        constructor method for that class--meaning TIESCALAR(),
  38.        TIEARRAY(), or TIEHASH().  (Typically these are arguments
  39.        such as might be passed to the dbminit() function of C.)
  40.        The object returned by the "new" method is also returned
  41.        by the tie() function, which would be useful if you wanted
  42.        to access other methods in CLASSNAME. (You don't actually
  43.        have to return a reference to a right "type" (e.g. HASH or
  44.        CLASSNAME) so long as it's a properly blessed object.)
  45.        You can also retrieve a reference to the underlying object
  46.        using the tied() function.
  47.  
  48.        Unlike dbmopen(), the tie() function will not use or
  49.        require a module for you--you need to do that explicitly
  50.        yourself.
  51.  
  52.  
  53.        Tying Scalars
  54.  
  55.        A class implementing a tied scalar should define the
  56.        following methods: TIESCALAR, FETCH, STORE, and possibly
  57.        DESTROY.
  58.  
  59.        Let's look at each in turn, using as an example a tie
  60.        class for scalars that allows the user to do something
  61.        like:
  62.  
  63.            tie $his_speed, 'Nice', getppid();
  64.            tie $my_speed,  'Nice', $$;
  65.  
  66.        And now whenever either of those variables is accessed,
  67.        its current system priority is retrieved and returned.  If
  68.        those variables are set, then the process's priority is
  69.        changed!
  70.  
  71.        We'll use Jarkko Hietaniemi <Jarkko.Hietaniemi@hut.fi>'s
  72.        BSD::Resource class (not included) to access the
  73.        PRIO_PROCESS, PRIO_MIN, and PRIO_MAX constants from your
  74.        system, as well as the getpriority() and setpriority()
  75.        system calls.  Here's the preamble of the class.
  76.  
  77.            package Nice;
  78.            use Carp;
  79.            use BSD::Resource;
  80.            use strict;
  81.            $Nice::DEBUG = 0 unless defined $Nice::DEBUG;
  82.  
  83.        TIESCALAR classname, LIST
  84.             This is the constructor for the class.  That means it
  85.             is expected to return a blessed reference to a new
  86.             scalar (probably anonymous) that it's creating.  For
  87.             example:
  88.  
  89.                 sub TIESCALAR {
  90.                     my $class = shift;
  91.                     my $pid = shift || $$; # 0 means me
  92.  
  93.                     if ($pid !~ /^\d+$/) {
  94.                         carp "Nice::Tie::Scalar got non-numeric pid $pid" if $^W;
  95.                         return undef;
  96.                     }
  97.  
  98.                     unless (kill 0, $pid) { # EPERM or ERSCH, no doubt
  99.                         carp "Nice::Tie::Scalar got bad pid $pid: $!" if $^W;
  100.                         return undef;
  101.                     }
  102.  
  103.                     return bless \$pid, $class;
  104.                 }
  105.  
  106.             This tie class has chosen to return an error rather
  107.             than raising an exception if its constructor should
  108.             fail.  While this is how dbmopen() works, other
  109.             classes may well not wish to be so forgiving.  It
  110.             checks the global variable $^W to see whether to emit
  111.             a bit of noise anyway.
  112.  
  113.        FETCH this
  114.             This method will be triggered every time the tied
  115.             variable is accessed (read).  It takes no arguments
  116.             beyond its self reference, which is the object
  117.             representing the scalar we're dealing with.  Since in
  118.             this case we're just using a SCALAR ref for the tied
  119.             scalar object, a simple $$self allows the method to
  120.             get at the real value stored there.  In our example
  121.             below, that real value is the process ID to which
  122.             we've tied our variable.
  123.  
  124.                 sub FETCH {
  125.                     my $self = shift;
  126.                     confess "wrong type" unless ref $self;
  127.                     croak "usage error" if @_;
  128.                     my $nicety;
  129.                     local($!) = 0;
  130.                     $nicety = getpriority(PRIO_PROCESS, $$self);
  131.                     if ($!) { croak "getpriority failed: $!" }
  132.                     return $nicety;
  133.                 }
  134.  
  135.             This time we've decided to blow up (raise an
  136.             exception) if the renice fails--there's no place for
  137.             us to return an error otherwise, and it's probably
  138.             the right thing to do.
  139.  
  140.        STORE this, value
  141.             This method will be triggered every time the tied
  142.             variable is set (assigned).  Beyond its self
  143.             reference, it also expects one (and only one)
  144.             argument--the new value the user is trying to assign.
  145.  
  146.                 sub STORE {
  147.                     my $self = shift;
  148.                     confess "wrong type" unless ref $self;
  149.                     my $new_nicety = shift;
  150.                     croak "usage error" if @_;
  151.  
  152.                     if ($new_nicety < PRIO_MIN) {
  153.                         carp sprintf
  154.                           "WARNING: priority %d less than minimum system priority %d",
  155.                               $new_nicety, PRIO_MIN if $^W;
  156.                         $new_nicety = PRIO_MIN;
  157.                     }
  158.  
  159.                     if ($new_nicety > PRIO_MAX) {
  160.                         carp sprintf
  161.                           "WARNING: priority %d greater than maximum system priority %d",
  162.                               $new_nicety, PRIO_MAX if $^W;
  163.                         $new_nicety = PRIO_MAX;
  164.                     }
  165.  
  166.                     unless (defined setpriority(PRIO_PROCESS, $$self, $new_nicety)) {
  167.                         confess "setpriority failed: $!";
  168.                     }
  169.                     return $new_nicety;
  170.                 }
  171.  
  172.        DESTROY this
  173.             This method will be triggered when the tied variable
  174.             needs to be destructed.  As with other object
  175.             classes, such a method is seldom ncessary, since Perl
  176.             deallocates its moribund object's memory for you
  177.             automatically--this isn't C++, you know.  We'll use a
  178.             DESTROY method here for debugging purposes only.
  179.  
  180.                 sub DESTROY {
  181.                     my $self = shift;
  182.                     confess "wrong type" unless ref $self;
  183.                     carp "[ Nice::DESTROY pid $$self ]" if $Nice::DEBUG;
  184.                 }
  185.  
  186.        That's about all there is to it.  Actually, it's more than
  187.        all there is to it, since we've done a few nice things
  188.        here for the sake of completeness, robustness, and general
  189.        aesthetics.  Simpler TIESCALAR classes are certainly
  190.        possible.
  191.  
  192.        Tying Arrays
  193.  
  194.        A class implementing a tied ordinary array should define
  195.        the following methods: TIEARRAY, FETCH, STORE, and perhaps
  196.        DESTROY.
  197.  
  198.        WARNING: Tied arrays are incomplete.  They are also
  199.        distinctly lacking something for the $#ARRAY access (which
  200.        is hard, as it's an lvalue), as well as the other obvious
  201.        array functions, like push(), pop(), shift(), unshift(),
  202.        and splice().
  203.  
  204.        For this discussion, we'll implement an array whose
  205.        indices are fixed at its creation.  If you try to access
  206.        anything beyond those bounds, you'll take an exception.
  207.        (Well, if you access an individual element; an aggregate
  208.        assignment would be missed.) For example:
  209.  
  210.            require Bounded_Array;
  211.            tie @ary, Bounded_Array, 2;
  212.            $| = 1;
  213.            for $i (0 .. 10) {
  214.                print "setting index $i: ";
  215.                $ary[$i] = 10 * $i;
  216.                $ary[$i] = 10 * $i;
  217.                print "value of elt $i now $ary[$i]\n";
  218.            }
  219.  
  220.        The preamble code for the class is as follows:
  221.  
  222.            package Bounded_Array;
  223.            use Carp;
  224.            use strict;
  225.  
  226.        TIEARRAY classname, LIST
  227.             This is the constructor for the class.  That means it
  228.             is expected to return a blessed reference through
  229.             which the new array (probably an anonymous ARRAY ref)
  230.             will be accessed.
  231.  
  232.             In our example, just to show you that you don't
  233.             really have to return an ARRAY reference, we'll
  234.             choose a HASH reference to represent our object.  A
  235.             HASH works out well as a generic record type: the
  236.             {BOUND} field will store the maximum bound allowed,
  237.             and the {ARRAY} field will hold the true ARRAY ref.
  238.             If someone outside the class tries to dereference the
  239.             object returned (doubtless thinking it an ARRAY ref),
  240.             they'll blow up.  This just goes to show you that you
  241.             should respect an object's privacy.
  242.  
  243.                 sub TIEARRAY {
  244.                     my $class = shift;
  245.                     my $bound = shift;
  246.                     confess "usage: tie(\@ary, 'Bounded_Array', max_subscript)"
  247.                         if @_ || $bound =~ /\D/;
  248.                     return bless {
  249.                         BOUND => $bound,
  250.                         ARRAY => [],
  251.                     }, $class;
  252.                 }
  253.  
  254.        FETCH this, index
  255.             This method will be triggered every time an
  256.             individual element the tied array is accessed (read).
  257.             It takes one argument beyond its self reference: the
  258.             index whose value we're trying to fetch.
  259.  
  260.  
  261.                 sub FETCH {
  262.                   my($self,$idx) = @_;
  263.                   if ($idx > $self->{BOUND}) {
  264.                     confess "Array OOB: $idx > $self->{BOUND}";
  265.                   }
  266.                   return $self->{ARRAY}[$idx];
  267.                 }
  268.  
  269.             As you may have noticed, the name of the FETCH method
  270.             (et al.) is the same for all accesses, even though
  271.             the constructors differ in names (TIESCALAR vs
  272.             TIEARRAY).  While in theory you could have the same
  273.             class servicing several tied types, in practice this
  274.             becomes cumbersome, and it's easiest to simply keep
  275.             them at one tie type per class.
  276.  
  277.        STORE this, index, value
  278.             This method will be triggered every time an element
  279.             in the tied array is set (written).  It takes two
  280.             arguments beyond its self reference: the index at
  281.             which we're trying to store something and the value
  282.             we're trying to put there.  For example:
  283.  
  284.                 sub STORE {
  285.                   my($self, $idx, $value) = @_;
  286.                   print "[STORE $value at $idx]\n" if _debug;
  287.                   if ($idx > $self->{BOUND} ) {
  288.                     confess "Array OOB: $idx > $self->{BOUND}";
  289.                   }
  290.                   return $self->{ARRAY}[$idx] = $value;
  291.                 }
  292.  
  293.        DESTROY this
  294.             This method will be triggered when the tied variable
  295.             needs to be destructed.  As with the sclar tie class,
  296.             this is almost never needed in a language that does
  297.             its own garbage collection, so this time we'll just
  298.             leave it out.
  299.  
  300.        The code we presented at the top of the tied array class
  301.        accesses many elements of the array, far more than we've
  302.        set the bounds to.  Therefore, it will blow up once they
  303.        try to access beyond the 2nd element of @ary, as the
  304.        following output demonstrates:
  305.  
  306.            setting index 0: value of elt 0 now 0
  307.            setting index 1: value of elt 1 now 10
  308.            setting index 2: value of elt 2 now 20
  309.            setting index 3: Array OOB: 3 > 2 at Bounded_Array.pm line 39
  310.                    Bounded_Array::FETCH called at testba line 12
  311.  
  312.  
  313.        Tying Hashes
  314.  
  315.        As the first Perl data type to be tied (see dbmopen()),
  316.        associative arrays have the most complete and useful tie()
  317.        implementation.  A class implementing a tied associative
  318.        array should define the following methods:  TIEHASH is the
  319.        constructor.  FETCH and STORE access the key and value
  320.        pairs.  EXISTS reports whether a key is present in the
  321.        hash, and DELETE deletes one.  CLEAR empties the hash by
  322.        deleting all the key and value pairs.  FIRSTKEY and
  323.        NEXTKEY implement the keys() and each() functions to
  324.        iterate over all the keys.  And DESTROY is called when the
  325.        tied variable is garbage collected.
  326.  
  327.        If this seems like a lot, then feel free to merely inherit
  328.        from the standard Tie::Hash module for most of your
  329.        methods, redefining only the interesting ones.  See the
  330.        Tie::Hash manpage for details.
  331.  
  332.        Remember that Perl distinguishes between a key not
  333.        existing in the hash, and the key existing in the hash but
  334.        having a corresponding value of undef.  The two
  335.        possibilities can be tested with the exists() and
  336.        defined() functions.
  337.  
  338.        Here's an example of a somewhat interesting tied hash
  339.        class:  it gives you a hash representing a particular
  340.        user's dotfiles.  You index into the hash with the name of
  341.        the file (minus the dot) and you get back that dotfile's
  342.        contents.  For example:
  343.  
  344.            use DotFiles;
  345.            tie %dot, DotFiles;
  346.            if ( $dot{profile} =~ /MANPATH/ ||
  347.                 $dot{login}   =~ /MANPATH/ ||
  348.                 $dot{cshrc}   =~ /MANPATH/    )
  349.            {
  350.                print "you seem to set your manpath\n";
  351.            }
  352.  
  353.        Or here's another sample of using our tied class:
  354.  
  355.            tie %him, DotFiles, 'daemon';
  356.            foreach $f ( keys %him ) {
  357.                printf "daemon dot file %s is size %d\n",
  358.                    $f, length $him{$f};
  359.            }
  360.  
  361.        In our tied hash DotFiles example, we use a regular hash
  362.        for the object containing several important fields, of
  363.        which only the {LIST} field will be what the user thinks
  364.        of as the real hash.
  365.  
  366.        USER whose dot files this object represents
  367.  
  368.        HOME where those dotfiles live
  369.  
  370.        CLOBBER
  371.             whether we should try to change or remove those dot
  372.             files
  373.  
  374.        LIST the hash of dotfile names and content mappings
  375.  
  376.        Here's the start of Dotfiles.pm:
  377.  
  378.            package DotFiles;
  379.            use Carp;
  380.            sub whowasi { (caller(1))[3] . '()' }
  381.            my $DEBUG = 0;
  382.            sub debug { $DEBUG = @_ ? shift : 1 }
  383.  
  384.        For our example, we want to able to emit debugging info to
  385.        help in tracing during development.  We keep also one
  386.        convenience function around internally to help print out
  387.        warnings; whowasi() returns the function name that calls
  388.        it.
  389.  
  390.        Here are the methods for the DotFiles tied hash.
  391.  
  392.        TIEHASH classname, LIST
  393.             This is the constructor for the class.  That means it
  394.             is expected to return a blessed reference through
  395.             which the new object (probably but not necessarily an
  396.             anonymous hash) will be accessed.
  397.  
  398.             Here's the constructor:
  399.  
  400.                 sub TIEHASH {
  401.                     my $self = shift;
  402.                     my $user = shift || $>;
  403.                     my $dotdir = shift || '';
  404.                     croak "usage: @{[&whowasi]} [USER [DOTDIR]]" if @_;
  405.                     $user = getpwuid($user) if $user =~ /^\d+$/;
  406.                     my $dir = (getpwnam($user))[7]
  407.                             || croak "@{[&whowasi]}: no user $user";
  408.                     $dir .= "/$dotdir" if $dotdir;
  409.  
  410.                     my $node = {
  411.                         USER    => $user,
  412.                         HOME    => $dir,
  413.                         LIST    => {},
  414.                         CLOBBER => 0,
  415.                     };
  416.  
  417.  
  418.  
  419.                     opendir(DIR, $dir)
  420.                             || croak "@{[&whowasi]}: can't opendir $dir: $!";
  421.                     foreach $dot ( grep /^\./ && -f "$dir/$_", readdir(DIR)) {
  422.                         $dot =~ s/^\.//;
  423.                         $node->{LIST}{$dot} = undef;
  424.                     }
  425.                     closedir DIR;
  426.                     return bless $node, $self;
  427.                 }
  428.  
  429.             It's probably worth mentioning that if you're going
  430.             to filetest the return values out of a readdir, you'd
  431.             better prepend the directory in question.  Otherwise,
  432.             since we didn't chdir() there, it would have been
  433.             testing the wrong file.
  434.  
  435.        FETCH this, key
  436.             This method will be triggered every time an element
  437.             in the tied hash is accessed (read).  It takes one
  438.             argument beyond its self reference: the key whose
  439.             value we're trying to fetch.
  440.  
  441.             Here's the fetch for our DotFiles example.
  442.  
  443.                 sub FETCH {
  444.                     carp &whowasi if $DEBUG;
  445.                     my $self = shift;
  446.                     my $dot = shift;
  447.                     my $dir = $self->{HOME};
  448.                     my $file = "$dir/.$dot";
  449.  
  450.                     unless (exists $self->{LIST}->{$dot} || -f $file) {
  451.                         carp "@{[&whowasi]}: no $dot file" if $DEBUG;
  452.                         return undef;
  453.                     }
  454.  
  455.                     if (defined $self->{LIST}->{$dot}) {
  456.                         return $self->{LIST}->{$dot};
  457.                     } else {
  458.                         return $self->{LIST}->{$dot} = `cat $dir/.$dot`;
  459.                     }
  460.                 }
  461.  
  462.             It was easy to write by having it call the Unix
  463.             cat(1) command, but it would probably be more
  464.             portable to open the file manually (and somewhat more
  465.             efficient).  Of course, since dot files are a Unixy
  466.             concept, we're not that concerned.
  467.  
  468.        STORE this, key, value
  469.             This method will be triggered every time an element
  470.             in the tied hash is set (written).  It takes two
  471.             arguments beyond its self reference: the index at
  472.             which we're trying to store something, and the value
  473.             we're trying to put there.
  474.  
  475.             Here in our DotFiles example, we'll be careful not to
  476.             let them try to overwrite the file unless they've
  477.             called the clobber() method on the original object
  478.             reference returned by tie().
  479.  
  480.                 sub STORE {
  481.                     carp &whowasi if $DEBUG;
  482.                     my $self = shift;
  483.                     my $dot = shift;
  484.                     my $value = shift;
  485.                     my $file = $self->{HOME} . "/.$dot";
  486.                     my $user = $self->{USER};
  487.  
  488.                     croak "@{[&whowasi]}: $file not clobberable"
  489.                         unless $self->{CLOBBER};
  490.  
  491.                     open(F, "> $file") || croak "can't open $file: $!";
  492.                     print F $value;
  493.                     close(F);
  494.                 }
  495.  
  496.             If they wanted to clobber something, they might say:
  497.  
  498.                 $ob = tie %daemon_dots, 'daemon';
  499.                 $ob->clobber(1);
  500.                 $daemon_dots{signature} = "A true daemon\n";
  501.  
  502.             Another way to lay hands on a reference to the
  503.             underlying object is to use the tied() function, so
  504.             they might alternately have set clobber using:
  505.  
  506.                 tie %daemon_dots, 'daemon';
  507.                 tied(%daemon_dots)->clobber(1);
  508.  
  509.             The clobber method is simply:
  510.  
  511.                 sub clobber {
  512.                     my $self = shift;
  513.                     $self->{CLOBBER} = @_ ? shift : 1;
  514.                 }
  515.  
  516.        DELETE this, key
  517.             This method is triggered when we remove an element
  518.             from the hash, typically by using the delete()
  519.             function.  Again, we'll be careful to check whether
  520.             they really want to clobber files.
  521.  
  522.                 sub DELETE   {
  523.                     carp &whowasi if $DEBUG;
  524.  
  525.                     my $self = shift;
  526.                     my $dot = shift;
  527.                     my $file = $self->{HOME} . "/.$dot";
  528.                     croak "@{[&whowasi]}: won't remove file $file"
  529.                         unless $self->{CLOBBER};
  530.                     delete $self->{LIST}->{$dot};
  531.                     unlink($file) || carp "@{[&whowasi]}: can't unlink $file: $!";
  532.                 }
  533.  
  534.        CLEAR this
  535.             This method is triggered when the whole hash is to be
  536.             cleared, usually by assigning the empty list to it.
  537.  
  538.             In our example, that would remove all the user's
  539.             dotfiles!  It's such a dangerous thing that they'll
  540.             have to set CLOBBER to something higher than 1 to
  541.             make it happen.
  542.  
  543.                 sub CLEAR    {
  544.                     carp &whowasi if $DEBUG;
  545.                     my $self = shift;
  546.                     croak "@{[&whowasi]}: won't remove all dotfiles for $self->{USER}"
  547.                         unless $self->{CLOBBER} > 1;
  548.                     my $dot;
  549.                     foreach $dot ( keys %{$self->{LIST}}) {
  550.                         $self->DELETE($dot);
  551.                     }
  552.                 }
  553.  
  554.        EXISTS this, key
  555.             This method is triggered when the user uses the
  556.             exists() function on a particular hash.  In our
  557.             example, we'll look at the {LIST} hash element for
  558.             this:
  559.  
  560.                 sub EXISTS   {
  561.                     carp &whowasi if $DEBUG;
  562.                     my $self = shift;
  563.                     my $dot = shift;
  564.                     return exists $self->{LIST}->{$dot};
  565.                 }
  566.  
  567.        FIRSTKEY this
  568.             This method will be triggered when the user is going
  569.             to iterate through the hash, such as via a keys() or
  570.             each() call.
  571.  
  572.  
  573.  
  574.                 sub FIRSTKEY {
  575.                     carp &whowasi if $DEBUG;
  576.                     my $self = shift;
  577.                     my $a = keys %{$self->{LIST}};          # reset each() iterator
  578.                     each %{$self->{LIST}}
  579.                 }
  580.  
  581.        NEXTKEY this, lastkey
  582.             This method gets triggered during a keys() or each()
  583.             iteration.  It has a second argument which is the
  584.             last key that had been accessed.  This is useful if
  585.             you're carrying about ordering or calling the
  586.             iterator from more than one sequence, or not really
  587.             storing things in a hash anywhere.
  588.  
  589.             For our example, we our using a real hash so we'll
  590.             just do the simple thing, but we'll have to indirect
  591.             through the LIST field.
  592.  
  593.                 sub NEXTKEY  {
  594.                     carp &whowasi if $DEBUG;
  595.                     my $self = shift;
  596.                     return each %{ $self->{LIST} }
  597.                 }
  598.  
  599.        DESTROY this
  600.             This method is triggered when a tied hash is about to
  601.             go out of scope.  You don't really need it unless
  602.             you're trying to add debugging or have auxiliary
  603.             state to clean up.  Here's a very simple function:
  604.  
  605.                 sub DESTROY  {
  606.                     carp &whowasi if $DEBUG;
  607.                 }
  608.  
  609.        Note that functions such as keys() and values() may return
  610.        huge array values when used on large objects, like DBM
  611.        files.  You may prefer to use the each() function to
  612.        iterate over such.  Example:
  613.  
  614.            # print out history file offsets
  615.            use NDBM_File;
  616.            tie(%HIST, NDBM_File, '/usr/lib/news/history', 1, 0);
  617.            while (($key,$val) = each %HIST) {
  618.                print $key, ' = ', unpack('L',$val), "\n";
  619.            }
  620.            untie(%HIST);
  621.  
  622.  
  623.  
  624.        Tying FileHandles
  625.  
  626.        This isn't implemented yet.  Sorry; maybe someday.
  627.  
  628. SEE ALSO
  629.        See the DB_File manpage or the Config manpage for some
  630.        interesting tie() implementations.
  631.  
  632. BUGS
  633.        Tied arrays are incomplete.  They are also distinctly
  634.        lacking something for the $#ARRAY access (which is hard,
  635.        as it's an lvalue), as well as the other obvious array
  636.        functions, like push(), pop(), shift(), unshift(), and
  637.        splice().
  638.  
  639.        You cannot easily tie a multilevel data structure (such as
  640.        a hash of hashes) to a dbm file.  The first problem is
  641.        that all but GDBM and Berkeley DB have size limitations,
  642.        but beyond that, you also have problems with how
  643.        references are to be represented on disk.  One
  644.        experimental module that does attempt to partially address
  645.        this need is the MLDBM module.  Check your nearest CPAN
  646.        site as described in the perlmod manpage for source code
  647.        to MLDBM.
  648.  
  649. AUTHOR
  650.        Tom Christiansen
  651.