home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 1996 July / AMIGA_1996_7.BIN / ausgabe_7_96 / pd-programmierung / perl5_002bin.lha / man / catp / perltie.0 < prev    next >
Text File  |  1996-03-02  |  57KB  |  859 lines

  1.  
  2.  
  3.  
  4. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  5.  
  6.  
  7. NNNNAAAAMMMMEEEE
  8.        perltie - how to hide an object class in a simple variable
  9.  
  10. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  11.         ttttiiiieeee VVVVAAAARRRRIIIIAAAABBBBLLLLEEEE,,,, CCCCLLLLAAAASSSSSSSSNNNNAAAAMMMMEEEE,,,, LLLLIIIISSSSTTTT
  12.  
  13.         $$$$oooobbbbjjjjeeeecccctttt ==== ttttiiiieeeedddd VVVVAAAARRRRIIIIAAAABBBBLLLLEEEE
  14.  
  15.         uuuunnnnttttiiiieeee VVVVAAAARRRRIIIIAAAABBBBLLLLEEEE
  16.  
  17.  
  18. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  19.        Prior to release 5.0 of Perl, a programmer could use
  20.        _d_b_m_o_p_e_n_(_) to magically connect an on-disk database in the
  21.        standard Unix _d_b_m(3x) format to a %%%%HHHHAAAASSSSHHHH in their program.
  22.        However, their Perl was either built with one particular
  23.        dbm library or another, but not both, and you couldn't
  24.        extend this mechanism to other packages or types of
  25.        variables.
  26.  
  27.        Now you can.
  28.  
  29.        The _t_i_e_(_) function binds a variable to a class (package)
  30.        that will provide the implementation for access methods
  31.        for that variable.  Once this magic has been performed,
  32.        accessing a tied variable automatically triggers method
  33.        calls in the proper class.  All of the complexity of the
  34.        class is hidden behind magic methods calls.  The method
  35.        names are in ALL CAPS, which is a convention that Perl
  36.        uses to indicate that they're called implicitly rather
  37.        than explicitly--just like the _B_E_G_I_N_(_) and _E_N_D_(_)
  38.        functions.
  39.  
  40.        In the _t_i_e_(_) call, VVVVAAAARRRRIIIIAAAABBBBLLLLEEEE is the name of the variable to
  41.        be enchanted.  CCCCLLLLAAAASSSSSSSSNNNNAAAAMMMMEEEE is the name of a class
  42.        implementing objects of the correct type.  Any additional
  43.        arguments in the LLLLIIIISSSSTTTT are passed to the appropriate
  44.        constructor method for that class--meaning _T_I_E_S_C_A_L_A_R_(_),
  45.        _T_I_E_A_R_R_A_Y_(_), or _T_I_E_H_A_S_H_(_).  (Typically these are arguments
  46.        such as might be passed to the _d_b_m_i_n_i_t_(_) function of C.)
  47.        The object returned by the "new" method is also returned
  48.        by the _t_i_e_(_) function, which would be useful if you wanted
  49.        to access other methods in CCCCLLLLAAAASSSSSSSSNNNNAAAAMMMMEEEE. (You don't actually
  50.        have to return a reference to a right "type" (e.g. HASH or
  51.        CCCCLLLLAAAASSSSSSSSNNNNAAAAMMMMEEEE) so long as it's a properly blessed object.)
  52.        You can also retrieve a reference to the underlying object
  53.        using the _t_i_e_d_(_) function.
  54.  
  55.        Unlike _d_b_m_o_p_e_n_(_), the _t_i_e_(_) function will not uuuusssseeee or
  56.        rrrreeeeqqqquuuuiiiirrrreeee a module for you--you need to do that explicitly
  57.        yourself.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. 12/Feb/96                perl 5.002 with                        1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  71.  
  72.  
  73.        TTTTyyyyiiiinnnngggg SSSSccccaaaallllaaaarrrrssss
  74.  
  75.        A class implementing a tied scalar should define the
  76.        following methods: TIESCALAR, FETCH, STORE, and possibly
  77.        DESTROY.
  78.  
  79.        Let's look at each in turn, using as an example a tie
  80.        class for scalars that allows the user to do something
  81.        like:
  82.  
  83.            ttttiiiieeee $$$$hhhhiiiissss____ssssppppeeeeeeeedddd,,,, ''''NNNNiiiicccceeee'''',,,, ggggeeeettttppppppppiiiidddd(((())));;;;
  84.            ttttiiiieeee $$$$mmmmyyyy____ssssppppeeeeeeeedddd,,,,  ''''NNNNiiiicccceeee'''',,,, $$$$$$$$;;;;
  85.  
  86.        And now whenever either of those variables is accessed,
  87.        its current system priority is retrieved and returned.  If
  88.        those variables are set, then the process's priority is
  89.        changed!
  90.  
  91.        We'll use Jarkko Hietaniemi _<_J_a_r_k_k_o_._H_i_e_t_a_n_i_e_m_i_@_h_u_t_._f_i_>'s
  92.        BSD::Resource class (not included) to access the
  93.        PRIO_PROCESS, PRIO_MIN, and PRIO_MAX constants from your
  94.        system, as well as the _g_e_t_p_r_i_o_r_i_t_y_(_) and _s_e_t_p_r_i_o_r_i_t_y_(_)
  95.        system calls.  Here's the preamble of the class.
  96.  
  97.            ppppaaaacccckkkkaaaaggggeeee NNNNiiiicccceeee;;;;
  98.            uuuusssseeee CCCCaaaarrrrpppp;;;;
  99.            uuuusssseeee BBBBSSSSDDDD::::::::RRRReeeessssoooouuuurrrrcccceeee;;;;
  100.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  101.            $$$$NNNNiiiicccceeee::::::::DDDDEEEEBBBBUUUUGGGG ==== 0000 uuuunnnnlllleeeessssssss ddddeeeeffffiiiinnnneeeedddd $$$$NNNNiiiicccceeee::::::::DDDDEEEEBBBBUUUUGGGG;;;;
  102.  
  103.  
  104.        TIESCALAR classname, LIST
  105.             This is the constructor for the class.  That means it
  106.             is expected to return a blessed reference to a new
  107.             scalar (probably anonymous) that it's creating.  For
  108.             example:
  109.  
  110.                 ssssuuuubbbb TTTTIIIIEEEESSSSCCCCAAAALLLLAAAARRRR {{{{
  111.                     mmmmyyyy $$$$ccccllllaaaassssssss ==== sssshhhhiiiifffftttt;;;;
  112.                     mmmmyyyy $$$$ppppiiiidddd ==== sssshhhhiiiifffftttt |||||||| $$$$$$$$;;;; #### 0000 mmmmeeeeaaaannnnssss mmmmeeee
  113.  
  114.                     iiiiffff (((($$$$ppppiiiidddd !!!!~~~~ ////^^^^\\\\dddd++++$$$$////)))) {{{{
  115.                         ccccaaaarrrrpppp """"NNNNiiiicccceeee::::::::TTTTiiiieeee::::::::SSSSccccaaaallllaaaarrrr ggggooootttt nnnnoooonnnn----nnnnuuuummmmeeeerrrriiiicccc ppppiiiidddd $$$$ppppiiiidddd"""" iiiiffff $$$$^^^^WWWW;;;;
  116.                         rrrreeeettttuuuurrrrnnnn uuuunnnnddddeeeeffff;;;;
  117.                     }}}}
  118.  
  119.                     uuuunnnnlllleeeessssssss ((((kkkkiiiillllllll 0000,,,, $$$$ppppiiiidddd)))) {{{{ #### EEEEPPPPEEEERRRRMMMM oooorrrr EEEERRRRSSSSCCCCHHHH,,,, nnnnoooo ddddoooouuuubbbbtttt
  120.                         ccccaaaarrrrpppp """"NNNNiiiicccceeee::::::::TTTTiiiieeee::::::::SSSSccccaaaallllaaaarrrr ggggooootttt bbbbaaaadddd ppppiiiidddd $$$$ppppiiiidddd:::: $$$$!!!!"""" iiiiffff $$$$^^^^WWWW;;;;
  121.                         rrrreeeettttuuuurrrrnnnn uuuunnnnddddeeeeffff;;;;
  122.                     }}}}
  123.  
  124.                     rrrreeeettttuuuurrrrnnnn bbbblllleeeessssssss \\\\$$$$ppppiiiidddd,,,, $$$$ccccllllaaaassssssss;;;;
  125.                 }}}}
  126.  
  127.  
  128.  
  129.  
  130. 12/Feb/96                perl 5.002 with                        2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  137.  
  138.  
  139.             This tie class has chosen to return an error rather
  140.             than raising an exception if its constructor should
  141.             fail.  While this is how _d_b_m_o_p_e_n_(_) works, other
  142.             classes may well not wish to be so forgiving.  It
  143.             checks the global variable $$$$^^^^WWWW to see whether to emit
  144.             a bit of noise anyway.
  145.  
  146.        FETCH this
  147.             This method will be triggered every time the tied
  148.             variable is accessed (read).  It takes no arguments
  149.             beyond its self reference, which is the object
  150.             representing the scalar we're dealing with.  Since in
  151.             this case we're just using a SCALAR ref for the tied
  152.             scalar object, a simple $$self allows the method to
  153.             get at the real value stored there.  In our example
  154.             below, that real value is the process ID to which
  155.             we've tied our variable.
  156.  
  157.                 ssssuuuubbbb FFFFEEEETTTTCCCCHHHH {{{{
  158.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  159.                     ccccoooonnnnffffeeeessssssss """"wwwwrrrroooonnnngggg ttttyyyyppppeeee"""" uuuunnnnlllleeeessssssss rrrreeeeffff $$$$sssseeeellllffff;;;;
  160.                     ccccrrrrooooaaaakkkk """"uuuussssaaaaggggeeee eeeerrrrrrrroooorrrr"""" iiiiffff @@@@____;;;;
  161.                     mmmmyyyy $$$$nnnniiiicccceeeettttyyyy;;;;
  162.                     llllooooccccaaaallll(((($$$$!!!!)))) ==== 0000;;;;
  163.                     $$$$nnnniiiicccceeeettttyyyy ==== ggggeeeettttpppprrrriiiioooorrrriiiittttyyyy((((PPPPRRRRIIIIOOOO____PPPPRRRROOOOCCCCEEEESSSSSSSS,,,, $$$$$$$$sssseeeellllffff))));;;;
  164.                     iiiiffff (((($$$$!!!!)))) {{{{ ccccrrrrooooaaaakkkk """"ggggeeeettttpppprrrriiiioooorrrriiiittttyyyy ffffaaaaiiiilllleeeedddd:::: $$$$!!!!"""" }}}}
  165.                     rrrreeeettttuuuurrrrnnnn $$$$nnnniiiicccceeeettttyyyy;;;;
  166.                 }}}}
  167.  
  168.             This time we've decided to blow up (raise an
  169.             exception) if the renice fails--there's no place for
  170.             us to return an error otherwise, and it's probably
  171.             the right thing to do.
  172.  
  173.        STORE this, value
  174.             This method will be triggered every time the tied
  175.             variable is set (assigned).  Beyond its self
  176.             reference, it also expects one (and only one)
  177.             argument--the new value the user is trying to assign.
  178.  
  179.                 ssssuuuubbbb SSSSTTTTOOOORRRREEEE {{{{
  180.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  181.                     ccccoooonnnnffffeeeessssssss """"wwwwrrrroooonnnngggg ttttyyyyppppeeee"""" uuuunnnnlllleeeessssssss rrrreeeeffff $$$$sssseeeellllffff;;;;
  182.                     mmmmyyyy $$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy ==== sssshhhhiiiifffftttt;;;;
  183.                     ccccrrrrooooaaaakkkk """"uuuussssaaaaggggeeee eeeerrrrrrrroooorrrr"""" iiiiffff @@@@____;;;;
  184.  
  185.                     iiiiffff (((($$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy <<<< PPPPRRRRIIIIOOOO____MMMMIIIINNNN)))) {{{{
  186.                         ccccaaaarrrrpppp sssspppprrrriiiinnnnttttffff
  187.                           """"WWWWAAAARRRRNNNNIIIINNNNGGGG:::: pppprrrriiiioooorrrriiiittttyyyy %%%%dddd lllleeeessssssss tttthhhhaaaannnn mmmmiiiinnnniiiimmmmuuuummmm ssssyyyysssstttteeeemmmm pppprrrriiiioooorrrriiiittttyyyy %%%%dddd"""",,,,
  188.                               $$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy,,,, PPPPRRRRIIIIOOOO____MMMMIIIINNNN iiiiffff $$$$^^^^WWWW;;;;
  189.                         $$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy ==== PPPPRRRRIIIIOOOO____MMMMIIIINNNN;;;;
  190.                     }}}}
  191.  
  192.  
  193.  
  194.  
  195.  
  196. 12/Feb/96                perl 5.002 with                        3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  203.  
  204.  
  205.                     iiiiffff (((($$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy >>>> PPPPRRRRIIIIOOOO____MMMMAAAAXXXX)))) {{{{
  206.                         ccccaaaarrrrpppp sssspppprrrriiiinnnnttttffff
  207.                           """"WWWWAAAARRRRNNNNIIIINNNNGGGG:::: pppprrrriiiioooorrrriiiittttyyyy %%%%dddd ggggrrrreeeeaaaatttteeeerrrr tttthhhhaaaannnn mmmmaaaaxxxxiiiimmmmuuuummmm ssssyyyysssstttteeeemmmm pppprrrriiiioooorrrriiiittttyyyy %%%%dddd"""",,,,
  208.                               $$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy,,,, PPPPRRRRIIIIOOOO____MMMMAAAAXXXX iiiiffff $$$$^^^^WWWW;;;;
  209.                         $$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy ==== PPPPRRRRIIIIOOOO____MMMMAAAAXXXX;;;;
  210.                     }}}}
  211.  
  212.                     uuuunnnnlllleeeessssssss ((((ddddeeeeffffiiiinnnneeeedddd sssseeeettttpppprrrriiiioooorrrriiiittttyyyy((((PPPPRRRRIIIIOOOO____PPPPRRRROOOOCCCCEEEESSSSSSSS,,,, $$$$$$$$sssseeeellllffff,,,, $$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy)))))))) {{{{
  213.                         ccccoooonnnnffffeeeessssssss """"sssseeeettttpppprrrriiiioooorrrriiiittttyyyy ffffaaaaiiiilllleeeedddd:::: $$$$!!!!"""";;;;
  214.                     }}}}
  215.                     rrrreeeettttuuuurrrrnnnn $$$$nnnneeeewwww____nnnniiiicccceeeettttyyyy;;;;
  216.                 }}}}
  217.  
  218.  
  219.        DESTROY this
  220.             This method will be triggered when the tied variable
  221.             needs to be destructed.  As with other object
  222.             classes, such a method is seldom ncessary, since Perl
  223.             deallocates its moribund object's memory for you
  224.             automatically--this isn't C++, you know.  We'll use a
  225.             DESTROY method here for debugging purposes only.
  226.  
  227.                 ssssuuuubbbb DDDDEEEESSSSTTTTRRRROOOOYYYY {{{{
  228.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  229.                     ccccoooonnnnffffeeeessssssss """"wwwwrrrroooonnnngggg ttttyyyyppppeeee"""" uuuunnnnlllleeeessssssss rrrreeeeffff $$$$sssseeeellllffff;;;;
  230.                     ccccaaaarrrrpppp """"[[[[ NNNNiiiicccceeee::::::::DDDDEEEESSSSTTTTRRRROOOOYYYY ppppiiiidddd $$$$$$$$sssseeeellllffff ]]]]"""" iiiiffff $$$$NNNNiiiicccceeee::::::::DDDDEEEEBBBBUUUUGGGG;;;;
  231.                 }}}}
  232.  
  233.  
  234.        That's about all there is to it.  Actually, it's more than
  235.        all there is to it, since we've done a few nice things
  236.        here for the sake of completeness, robustness, and general
  237.        aesthetics.  Simpler TIESCALAR classes are certainly
  238.        possible.
  239.  
  240.        TTTTyyyyiiiinnnngggg AAAArrrrrrrraaaayyyyssss
  241.  
  242.        A class implementing a tied ordinary array should define
  243.        the following methods: TIEARRAY, FETCH, STORE, and perhaps
  244.        DESTROY.
  245.  
  246.        WWWWAAAARRRRNNNNIIIINNNNGGGG: Tied arrays are _i_n_c_o_m_p_l_e_t_e.  They are also
  247.        distinctly lacking something for the $$$$####AAAARRRRRRRRAAAAYYYY access (which
  248.        is hard, as it's an lvalue), as well as the other obvious
  249.        array functions, like _p_u_s_h_(_), _p_o_p_(_), _s_h_i_f_t_(_), _u_n_s_h_i_f_t_(_),
  250.        and _s_p_l_i_c_e_(_).
  251.  
  252.        For this discussion, we'll implement an array whose
  253.        indices are fixed at its creation.  If you try to access
  254.        anything beyond those bounds, you'll take an exception.
  255.        (Well, if you access an individual element; an aggregate
  256.        assignment would be missed.) For example:
  257.  
  258.  
  259.  
  260.  
  261.  
  262. 12/Feb/96                perl 5.002 with                        4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  269.  
  270.  
  271.            rrrreeeeqqqquuuuiiiirrrreeee BBBBoooouuuunnnnddddeeeedddd____AAAArrrrrrrraaaayyyy;;;;
  272.            ttttiiiieeee @@@@aaaarrrryyyy,,,, BBBBoooouuuunnnnddddeeeedddd____AAAArrrrrrrraaaayyyy,,,, 2222;;;;
  273.            $$$$|||| ==== 1111;;;;
  274.            ffffoooorrrr $$$$iiii ((((0000 ........ 11110000)))) {{{{
  275.                pppprrrriiiinnnntttt """"sssseeeettttttttiiiinnnngggg iiiinnnnddddeeeexxxx $$$$iiii:::: """";;;;
  276.                $$$$aaaarrrryyyy[[[[$$$$iiii]]]] ==== 11110000 **** $$$$iiii;;;;
  277.                $$$$aaaarrrryyyy[[[[$$$$iiii]]]] ==== 11110000 **** $$$$iiii;;;;
  278.                pppprrrriiiinnnntttt """"vvvvaaaalllluuuueeee ooooffff eeeelllltttt $$$$iiii nnnnoooowwww $$$$aaaarrrryyyy[[[[$$$$iiii]]]]\\\\nnnn"""";;;;
  279.            }}}}
  280.  
  281.        The preamble code for the class is as follows:
  282.  
  283.            ppppaaaacccckkkkaaaaggggeeee BBBBoooouuuunnnnddddeeeedddd____AAAArrrrrrrraaaayyyy;;;;
  284.            uuuusssseeee CCCCaaaarrrrpppp;;;;
  285.            uuuusssseeee ssssttttrrrriiiicccctttt;;;;
  286.  
  287.  
  288.        TIEARRAY classname, LIST
  289.             This is the constructor for the class.  That means it
  290.             is expected to return a blessed reference through
  291.             which the new array (probably an anonymous ARRAY ref)
  292.             will be accessed.
  293.  
  294.             In our example, just to show you that you don't
  295.             _r_e_a_l_l_y have to return an ARRAY reference, we'll
  296.             choose a HASH reference to represent our object.  A
  297.             HASH works out well as a generic record type: the
  298.             {{{{BBBBOOOOUUUUNNNNDDDD}}}} field will store the maximum bound allowed,
  299.             and the C<{ARRAY} field will hold the true ARRAY ref.
  300.             If someone outside the class tries to dereference the
  301.             object returned (doubtless thinking it an ARRAY ref),
  302.             they'll blow up.  This just goes to show you that you
  303.             should respect an object's privacy.
  304.  
  305.                 ssssuuuubbbb TTTTIIIIEEEEAAAARRRRRRRRAAAAYYYY {{{{
  306.                     mmmmyyyy $$$$ccccllllaaaassssssss ==== sssshhhhiiiifffftttt;;;;
  307.                     mmmmyyyy $$$$bbbboooouuuunnnndddd ==== sssshhhhiiiifffftttt;;;;
  308.                     ccccoooonnnnffffeeeessssssss """"uuuussssaaaaggggeeee:::: ttttiiiieeee((((\\\\@@@@aaaarrrryyyy,,,, ''''BBBBoooouuuunnnnddddeeeedddd____AAAArrrrrrrraaaayyyy'''',,,, mmmmaaaaxxxx____ssssuuuubbbbssssccccrrrriiiipppptttt))))""""
  309.                         iiiiffff @@@@____ |||||||| $$$$bbbboooouuuunnnndddd ====~~~~ ////\\\\DDDD////;;;;
  310.                     rrrreeeettttuuuurrrrnnnn bbbblllleeeessssssss {{{{
  311.                         BBBBOOOOUUUUNNNNDDDD ====>>>> $$$$bbbboooouuuunnnndddd,,,,
  312.                         AAAARRRRRRRRAAAAYYYY ====>>>> [[[[]]]],,,,
  313.                     }}}},,,, $$$$ccccllllaaaassssssss;;;;
  314.                 }}}}
  315.  
  316.  
  317.        FETCH this, index
  318.             This method will be triggered every time an
  319.             individual element the tied array is accessed (read).
  320.             It takes one argument beyond its self reference: the
  321.             index whose value we're trying to fetch.
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. 12/Feb/96                perl 5.002 with                        5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  335.  
  336.  
  337.                 ssssuuuubbbb FFFFEEEETTTTCCCCHHHH {{{{
  338.                   mmmmyyyy(((($$$$sssseeeellllffff,,,,$$$$iiiiddddxxxx)))) ==== @@@@____;;;;
  339.                   iiiiffff (((($$$$iiiiddddxxxx >>>> $$$$sssseeeellllffff---->>>>{{{{BBBBOOOOUUUUNNNNDDDD}}}})))) {{{{
  340.                     ccccoooonnnnffffeeeessssssss """"AAAArrrrrrrraaaayyyy OOOOOOOOBBBB:::: $$$$iiiiddddxxxx >>>> $$$$sssseeeellllffff---->>>>{{{{BBBBOOOOUUUUNNNNDDDD}}}}"""";;;;
  341.                   }}}}
  342.                   rrrreeeettttuuuurrrrnnnn $$$$sssseeeellllffff---->>>>{{{{AAAARRRRRRRRAAAAYYYY}}}}[[[[$$$$iiiiddddxxxx]]]];;;;
  343.                 }}}}
  344.  
  345.             As you may have noticed, the name of the FETCH method
  346.             (et al.) is the same for all accesses, even though
  347.             the constructors differ in names (TIESCALAR vs
  348.             TIEARRAY).  While in theory you could have the same
  349.             class servicing several tied types, in practice this
  350.             becomes cumbersome, and it's easiest to simply keep
  351.             them at one tie type per class.
  352.  
  353.        STORE this, index, value
  354.             This method will be triggered every time an element
  355.             in the tied array is set (written).  It takes two
  356.             arguments beyond its self reference: the index at
  357.             which we're trying to store something and the value
  358.             we're trying to put there.  For example:
  359.  
  360.                 ssssuuuubbbb SSSSTTTTOOOORRRREEEE {{{{
  361.                   mmmmyyyy(((($$$$sssseeeellllffff,,,, $$$$iiiiddddxxxx,,,, $$$$vvvvaaaalllluuuueeee)))) ==== @@@@____;;;;
  362.                   pppprrrriiiinnnntttt """"[[[[SSSSTTTTOOOORRRREEEE $$$$vvvvaaaalllluuuueeee aaaatttt $$$$iiiiddddxxxx]]]]\\\\nnnn"""" iiiiffff ____ddddeeeebbbbuuuugggg;;;;
  363.                   iiiiffff (((($$$$iiiiddddxxxx >>>> $$$$sssseeeellllffff---->>>>{{{{BBBBOOOOUUUUNNNNDDDD}}}} )))) {{{{
  364.                     ccccoooonnnnffffeeeessssssss """"AAAArrrrrrrraaaayyyy OOOOOOOOBBBB:::: $$$$iiiiddddxxxx >>>> $$$$sssseeeellllffff---->>>>{{{{BBBBOOOOUUUUNNNNDDDD}}}}"""";;;;
  365.                   }}}}
  366.                   rrrreeeettttuuuurrrrnnnn $$$$sssseeeellllffff---->>>>{{{{AAAARRRRRRRRAAAAYYYY}}}}[[[[$$$$iiiiddddxxxx]]]] ==== $$$$vvvvaaaalllluuuueeee;;;;
  367.                 }}}}
  368.  
  369.  
  370.        DESTROY this
  371.             This method will be triggered when the tied variable
  372.             needs to be destructed.  As with the sclar tie class,
  373.             this is almost never needed in a language that does
  374.             its own garbage collection, so this time we'll just
  375.             leave it out.
  376.  
  377.        The code we presented at the top of the tied array class
  378.        accesses many elements of the array, far more than we've
  379.        set the bounds to.  Therefore, it will blow up once they
  380.        try to access beyond the 2nd element of @@@@aaaarrrryyyy, as the
  381.        following output demonstrates:
  382.  
  383.            sssseeeettttttttiiiinnnngggg iiiinnnnddddeeeexxxx 0000:::: vvvvaaaalllluuuueeee ooooffff eeeelllltttt 0000 nnnnoooowwww 0000
  384.            sssseeeettttttttiiiinnnngggg iiiinnnnddddeeeexxxx 1111:::: vvvvaaaalllluuuueeee ooooffff eeeelllltttt 1111 nnnnoooowwww 11110000
  385.            sssseeeettttttttiiiinnnngggg iiiinnnnddddeeeexxxx 2222:::: vvvvaaaalllluuuueeee ooooffff eeeelllltttt 2222 nnnnoooowwww 22220000
  386.            sssseeeettttttttiiiinnnngggg iiiinnnnddddeeeexxxx 3333:::: AAAArrrrrrrraaaayyyy OOOOOOOOBBBB:::: 3333 >>>> 2222 aaaatttt BBBBoooouuuunnnnddddeeeedddd____AAAArrrrrrrraaaayyyy....ppppmmmm lllliiiinnnneeee 33339999
  387.                    BBBBoooouuuunnnnddddeeeedddd____AAAArrrrrrrraaaayyyy::::::::FFFFEEEETTTTCCCCHHHH ccccaaaalllllllleeeedddd aaaatttt tttteeeessssttttbbbbaaaa lllliiiinnnneeee 11112222
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. 12/Feb/96                perl 5.002 with                        6
  395.  
  396.  
  397.  
  398.  
  399.  
  400. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  401.  
  402.  
  403.        TTTTyyyyiiiinnnngggg HHHHaaaasssshhhheeeessss
  404.  
  405.        As the first Perl data type to be tied (see _d_b_m_o_p_e_n_(_)),
  406.        associative arrays have the most complete and useful _t_i_e_(_)
  407.        implementation.  A class implementing a tied associative
  408.        array should define the following methods:  TIEHASH is the
  409.        constructor.  FETCH and STORE access the key and value
  410.        pairs.  EXISTS reports whether a key is present in the
  411.        hash, and DELETE deletes one.  CLEAR empties the hash by
  412.        deleting all the key and value pairs.  FIRSTKEY and
  413.        NEXTKEY implement the _k_e_y_s_(_) and _e_a_c_h_(_) functions to
  414.        iterate over all the keys.  And DESTROY is called when the
  415.        tied variable is garbage collected.
  416.  
  417.        If this seems like a lot, then feel free to merely inherit
  418.        from the standard Tie::Hash module for most of your
  419.        methods, redefining only the interesting ones.  See the
  420.        _T_i_e_:_:_H_a_s_h manpage for details.
  421.  
  422.        Remember that Perl distinguishes between a key not
  423.        existing in the hash, and the key existing in the hash but
  424.        having a corresponding value of uuuunnnnddddeeeeffff.  The two
  425.        possibilities can be tested with the eeeexxxxiiiissssttttssss(((()))) and
  426.        ddddeeeeffffiiiinnnneeeedddd(((()))) functions.
  427.  
  428.        Here's an example of a somewhat interesting tied hash
  429.        class:  it gives you a hash representing a particular
  430.        user's dotfiles.  You index into the hash with the name of
  431.        the file (minus the dot) and you get back that dotfile's
  432.        contents.  For example:
  433.  
  434.            uuuusssseeee DDDDoooottttFFFFiiiilllleeeessss;;;;
  435.            ttttiiiieeee %%%%ddddooootttt,,,, DDDDoooottttFFFFiiiilllleeeessss;;;;
  436.            iiiiffff (((( $$$$ddddooootttt{{{{pppprrrrooooffffiiiilllleeee}}}} ====~~~~ ////MMMMAAAANNNNPPPPAAAATTTTHHHH//// ||||||||
  437.                 $$$$ddddooootttt{{{{llllooooggggiiiinnnn}}}}   ====~~~~ ////MMMMAAAANNNNPPPPAAAATTTTHHHH//// ||||||||
  438.                 $$$$ddddooootttt{{{{ccccsssshhhhrrrrcccc}}}}   ====~~~~ ////MMMMAAAANNNNPPPPAAAATTTTHHHH////    ))))
  439.            {{{{
  440.                pppprrrriiiinnnntttt """"yyyyoooouuuu sssseeeeeeeemmmm ttttoooo sssseeeetttt yyyyoooouuuurrrr mmmmaaaannnnppppaaaatttthhhh\\\\nnnn"""";;;;
  441.            }}}}
  442.  
  443.        Or here's another sample of using our tied class:
  444.  
  445.            ttttiiiieeee %%%%hhhhiiiimmmm,,,, DDDDoooottttFFFFiiiilllleeeessss,,,, ''''ddddaaaaeeeemmmmoooonnnn'''';;;;
  446.            ffffoooorrrreeeeaaaacccchhhh $$$$ffff (((( kkkkeeeeyyyyssss %%%%hhhhiiiimmmm )))) {{{{
  447.                pppprrrriiiinnnnttttffff """"ddddaaaaeeeemmmmoooonnnn ddddooootttt ffffiiiilllleeee %%%%ssss iiiissss ssssiiiizzzzeeee %%%%dddd\\\\nnnn"""",,,,
  448.                    $$$$ffff,,,, lllleeeennnnggggtttthhhh $$$$hhhhiiiimmmm{{{{$$$$ffff}}}};;;;
  449.            }}}}
  450.  
  451.        In our tied hash DotFiles example, we use a regular hash
  452.        for the object containing several important fields, of
  453.        which only the {{{{LLLLIIIISSSSTTTT}}}} field will be what the user thinks
  454.        of as the real hash.
  455.  
  456.  
  457.  
  458.  
  459.  
  460. 12/Feb/96                perl 5.002 with                        7
  461.  
  462.  
  463.  
  464.  
  465.  
  466. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  467.  
  468.  
  469.        USER whose dot files this object represents
  470.  
  471.        HOME where those dotfiles live
  472.  
  473.        CLOBBER
  474.             whether we should try to change or remove those dot
  475.             files
  476.  
  477.        LIST the hash of dotfile names and content mappings
  478.  
  479.        Here's the start of _D_o_t_f_i_l_e_s_._p_m:
  480.  
  481.            ppppaaaacccckkkkaaaaggggeeee DDDDoooottttFFFFiiiilllleeeessss;;;;
  482.            uuuusssseeee CCCCaaaarrrrpppp;;;;
  483.            ssssuuuubbbb wwwwhhhhoooowwwwaaaassssiiii {{{{ ((((ccccaaaalllllllleeeerrrr((((1111))))))))[[[[3333]]]] .... ''''(((())))'''' }}}}
  484.            mmmmyyyy $$$$DDDDEEEEBBBBUUUUGGGG ==== 0000;;;;
  485.            ssssuuuubbbb ddddeeeebbbbuuuugggg {{{{ $$$$DDDDEEEEBBBBUUUUGGGG ==== @@@@____ ???? sssshhhhiiiifffftttt :::: 1111 }}}}
  486.  
  487.        For our example, we want to able to emit debugging info to
  488.        help in tracing during development.  We keep also one
  489.        convenience function around internally to help print out
  490.        warnings; _w_h_o_w_a_s_i_(_) returns the function name that calls
  491.        it.
  492.  
  493.        Here are the methods for the DotFiles tied hash.
  494.  
  495.        TIEHASH classname, LIST
  496.             This is the constructor for the class.  That means it
  497.             is expected to return a blessed reference through
  498.             which the new object (probably but not necessarily an
  499.             anonymous hash) will be accessed.
  500.  
  501.             Here's the constructor:
  502.  
  503.                 ssssuuuubbbb TTTTIIIIEEEEHHHHAAAASSSSHHHH {{{{
  504.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  505.                     mmmmyyyy $$$$uuuusssseeeerrrr ==== sssshhhhiiiifffftttt |||||||| $$$$>>>>;;;;
  506.                     mmmmyyyy $$$$ddddoooottttddddiiiirrrr ==== sssshhhhiiiifffftttt |||||||| '''''''';;;;
  507.                     ccccrrrrooooaaaakkkk """"uuuussssaaaaggggeeee:::: @@@@{{{{[[[[&&&&wwwwhhhhoooowwwwaaaassssiiii]]]]}}}} [[[[UUUUSSSSEEEERRRR [[[[DDDDOOOOTTTTDDDDIIIIRRRR]]]]]]]]"""" iiiiffff @@@@____;;;;
  508.                     $$$$uuuusssseeeerrrr ==== ggggeeeettttppppwwwwuuuuiiiidddd(((($$$$uuuusssseeeerrrr)))) iiiiffff $$$$uuuusssseeeerrrr ====~~~~ ////^^^^\\\\dddd++++$$$$////;;;;
  509.                     mmmmyyyy $$$$ddddiiiirrrr ==== ((((ggggeeeettttppppwwwwnnnnaaaammmm(((($$$$uuuusssseeeerrrr))))))))[[[[7777]]]]
  510.                             |||||||| ccccrrrrooooaaaakkkk """"@@@@{{{{[[[[&&&&wwwwhhhhoooowwwwaaaassssiiii]]]]}}}}:::: nnnnoooo uuuusssseeeerrrr $$$$uuuusssseeeerrrr"""";;;;
  511.                     $$$$ddddiiiirrrr ....==== """"////$$$$ddddoooottttddddiiiirrrr"""" iiiiffff $$$$ddddoooottttddddiiiirrrr;;;;
  512.  
  513.                     mmmmyyyy $$$$nnnnooooddddeeee ==== {{{{
  514.                         UUUUSSSSEEEERRRR    ====>>>> $$$$uuuusssseeeerrrr,,,,
  515.                         HHHHOOOOMMMMEEEE    ====>>>> $$$$ddddiiiirrrr,,,,
  516.                         LLLLIIIISSSSTTTT    ====>>>> {{{{}}}},,,,
  517.                         CCCCLLLLOOOOBBBBBBBBEEEERRRR ====>>>> 0000,,,,
  518.                     }}}};;;;
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526. 12/Feb/96                perl 5.002 with                        8
  527.  
  528.  
  529.  
  530.  
  531.  
  532. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  533.  
  534.  
  535.                     ooooppppeeeennnnddddiiiirrrr((((DDDDIIIIRRRR,,,, $$$$ddddiiiirrrr))))
  536.                             |||||||| ccccrrrrooooaaaakkkk """"@@@@{{{{[[[[&&&&wwwwhhhhoooowwwwaaaassssiiii]]]]}}}}:::: ccccaaaannnn''''tttt ooooppppeeeennnnddddiiiirrrr $$$$ddddiiiirrrr:::: $$$$!!!!"""";;;;
  537.                     ffffoooorrrreeeeaaaacccchhhh $$$$ddddooootttt (((( ggggrrrreeeepppp ////^^^^\\\\....//// &&&&&&&& ----ffff """"$$$$ddddiiiirrrr////$$$$____"""",,,, rrrreeeeaaaaddddddddiiiirrrr((((DDDDIIIIRRRR)))))))) {{{{
  538.                         $$$$ddddooootttt ====~~~~ ssss////^^^^\\\\....////////;;;;
  539.                         $$$$nnnnooooddddeeee---->>>>{{{{LLLLIIIISSSSTTTT}}}}{{{{$$$$ddddooootttt}}}} ==== uuuunnnnddddeeeeffff;;;;
  540.                     }}}}
  541.                     cccclllloooosssseeeeddddiiiirrrr DDDDIIIIRRRR;;;;
  542.                     rrrreeeettttuuuurrrrnnnn bbbblllleeeessssssss $$$$nnnnooooddddeeee,,,, $$$$sssseeeellllffff;;;;
  543.                 }}}}
  544.  
  545.             It's probably worth mentioning that if you're going
  546.             to filetest the return values out of a readdir, you'd
  547.             better prepend the directory in question.  Otherwise,
  548.             since we didn't _c_h_d_i_r_(_) there, it would have been
  549.             testing the wrong file.
  550.  
  551.        FETCH this, key
  552.             This method will be triggered every time an element
  553.             in the tied hash is accessed (read).  It takes one
  554.             argument beyond its self reference: the key whose
  555.             value we're trying to fetch.
  556.  
  557.             Here's the fetch for our DotFiles example.
  558.  
  559.                 ssssuuuubbbb FFFFEEEETTTTCCCCHHHH {{{{
  560.                     ccccaaaarrrrpppp &&&&wwwwhhhhoooowwwwaaaassssiiii iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  561.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  562.                     mmmmyyyy $$$$ddddooootttt ==== sssshhhhiiiifffftttt;;;;
  563.                     mmmmyyyy $$$$ddddiiiirrrr ==== $$$$sssseeeellllffff---->>>>{{{{HHHHOOOOMMMMEEEE}}}};;;;
  564.                     mmmmyyyy $$$$ffffiiiilllleeee ==== """"$$$$ddddiiiirrrr////....$$$$ddddooootttt"""";;;;
  565.  
  566.                     uuuunnnnlllleeeessssssss ((((eeeexxxxiiiissssttttssss $$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}---->>>>{{{{$$$$ddddooootttt}}}} |||||||| ----ffff $$$$ffffiiiilllleeee)))) {{{{
  567.                         ccccaaaarrrrpppp """"@@@@{{{{[[[[&&&&wwwwhhhhoooowwwwaaaassssiiii]]]]}}}}:::: nnnnoooo $$$$ddddooootttt ffffiiiilllleeee"""" iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  568.                         rrrreeeettttuuuurrrrnnnn uuuunnnnddddeeeeffff;;;;
  569.                     }}}}
  570.  
  571.                     iiiiffff ((((ddddeeeeffffiiiinnnneeeedddd $$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}---->>>>{{{{$$$$ddddooootttt}}}})))) {{{{
  572.                         rrrreeeettttuuuurrrrnnnn $$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}---->>>>{{{{$$$$ddddooootttt}}}};;;;
  573.                     }}}} eeeellllsssseeee {{{{
  574.                         rrrreeeettttuuuurrrrnnnn $$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}---->>>>{{{{$$$$ddddooootttt}}}} ==== ````ccccaaaatttt $$$$ddddiiiirrrr////....$$$$ddddooootttt````;;;;
  575.                     }}}}
  576.                 }}}}
  577.  
  578.             It was easy to write by having it call the Unix
  579.             _c_a_t(1) command, but it would probably be more
  580.             portable to open the file manually (and somewhat more
  581.             efficient).  Of course, since dot files are a Unixy
  582.             concept, we're not that concerned.
  583.  
  584.        STORE this, key, value
  585.             This method will be triggered every time an element
  586.             in the tied hash is set (written).  It takes two
  587.             arguments beyond its self reference: the index at
  588.             which we're trying to store something, and the value
  589.  
  590.  
  591.  
  592. 12/Feb/96                perl 5.002 with                        9
  593.  
  594.  
  595.  
  596.  
  597.  
  598. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  599.  
  600.  
  601.             we're trying to put there.
  602.  
  603.             Here in our DotFiles example, we'll be careful not to
  604.             let them try to overwrite the file unless they've
  605.             called the _c_l_o_b_b_e_r_(_) method on the original object
  606.             reference returned by _t_i_e_(_).
  607.  
  608.                 ssssuuuubbbb SSSSTTTTOOOORRRREEEE {{{{
  609.                     ccccaaaarrrrpppp &&&&wwwwhhhhoooowwwwaaaassssiiii iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  610.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  611.                     mmmmyyyy $$$$ddddooootttt ==== sssshhhhiiiifffftttt;;;;
  612.                     mmmmyyyy $$$$vvvvaaaalllluuuueeee ==== sssshhhhiiiifffftttt;;;;
  613.                     mmmmyyyy $$$$ffffiiiilllleeee ==== $$$$sssseeeellllffff---->>>>{{{{HHHHOOOOMMMMEEEE}}}} .... """"////....$$$$ddddooootttt"""";;;;
  614.                     mmmmyyyy $$$$uuuusssseeeerrrr ==== $$$$sssseeeellllffff---->>>>{{{{UUUUSSSSEEEERRRR}}}};;;;
  615.  
  616.                     ccccrrrrooooaaaakkkk """"@@@@{{{{[[[[&&&&wwwwhhhhoooowwwwaaaassssiiii]]]]}}}}:::: $$$$ffffiiiilllleeee nnnnooootttt cccclllloooobbbbbbbbeeeerrrraaaabbbblllleeee""""
  617.                         uuuunnnnlllleeeessssssss $$$$sssseeeellllffff---->>>>{{{{CCCCLLLLOOOOBBBBBBBBEEEERRRR}}}};;;;
  618.  
  619.                     ooooppppeeeennnn((((FFFF,,,, """">>>> $$$$ffffiiiilllleeee"""")))) |||||||| ccccrrrrooooaaaakkkk """"ccccaaaannnn''''tttt ooooppppeeeennnn $$$$ffffiiiilllleeee:::: $$$$!!!!"""";;;;
  620.                     pppprrrriiiinnnntttt FFFF $$$$vvvvaaaalllluuuueeee;;;;
  621.                     cccclllloooosssseeee((((FFFF))));;;;
  622.                 }}}}
  623.  
  624.             If they wanted to clobber something, they might say:
  625.  
  626.                 $$$$oooobbbb ==== ttttiiiieeee %%%%ddddaaaaeeeemmmmoooonnnn____ddddoooottttssss,,,, ''''ddddaaaaeeeemmmmoooonnnn'''';;;;
  627.                 $$$$oooobbbb---->>>>cccclllloooobbbbbbbbeeeerrrr((((1111))));;;;
  628.                 $$$$ddddaaaaeeeemmmmoooonnnn____ddddoooottttssss{{{{ssssiiiiggggnnnnaaaattttuuuurrrreeee}}}} ==== """"AAAA ttttrrrruuuueeee ddddaaaaeeeemmmmoooonnnn\\\\nnnn"""";;;;
  629.  
  630.             Another way to lay hands on a reference to the
  631.             underlying object is to use the _t_i_e_d_(_) function, so
  632.             they might alternately have set clobber using:
  633.  
  634.                 ttttiiiieeee %%%%ddddaaaaeeeemmmmoooonnnn____ddddoooottttssss,,,, ''''ddddaaaaeeeemmmmoooonnnn'''';;;;
  635.                 ttttiiiieeeedddd((((%%%%ddddaaaaeeeemmmmoooonnnn____ddddoooottttssss))))---->>>>cccclllloooobbbbbbbbeeeerrrr((((1111))));;;;
  636.  
  637.             The clobber method is simply:
  638.  
  639.                 ssssuuuubbbb cccclllloooobbbbbbbbeeeerrrr {{{{
  640.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  641.                     $$$$sssseeeellllffff---->>>>{{{{CCCCLLLLOOOOBBBBBBBBEEEERRRR}}}} ==== @@@@____ ???? sssshhhhiiiifffftttt :::: 1111;;;;
  642.                 }}}}
  643.  
  644.  
  645.        DELETE this, key
  646.             This method is triggered when we remove an element
  647.             from the hash, typically by using the _d_e_l_e_t_e_(_)
  648.             function.  Again, we'll be careful to check whether
  649.             they really want to clobber files.
  650.  
  651.                 ssssuuuubbbb DDDDEEEELLLLEEEETTTTEEEE   {{{{
  652.                     ccccaaaarrrrpppp &&&&wwwwhhhhoooowwwwaaaassssiiii iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  653.  
  654.  
  655.  
  656.  
  657.  
  658. 12/Feb/96                perl 5.002 with                       10
  659.  
  660.  
  661.  
  662.  
  663.  
  664. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  665.  
  666.  
  667.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  668.                     mmmmyyyy $$$$ddddooootttt ==== sssshhhhiiiifffftttt;;;;
  669.                     mmmmyyyy $$$$ffffiiiilllleeee ==== $$$$sssseeeellllffff---->>>>{{{{HHHHOOOOMMMMEEEE}}}} .... """"////....$$$$ddddooootttt"""";;;;
  670.                     ccccrrrrooooaaaakkkk """"@@@@{{{{[[[[&&&&wwwwhhhhoooowwwwaaaassssiiii]]]]}}}}:::: wwwwoooonnnn''''tttt rrrreeeemmmmoooovvvveeee ffffiiiilllleeee $$$$ffffiiiilllleeee""""
  671.                         uuuunnnnlllleeeessssssss $$$$sssseeeellllffff---->>>>{{{{CCCCLLLLOOOOBBBBBBBBEEEERRRR}}}};;;;
  672.                     ddddeeeelllleeeetttteeee $$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}---->>>>{{{{$$$$ddddooootttt}}}};;;;
  673.                     uuuunnnnlllliiiinnnnkkkk(((($$$$ffffiiiilllleeee)))) |||||||| ccccaaaarrrrpppp """"@@@@{{{{[[[[&&&&wwwwhhhhoooowwwwaaaassssiiii]]]]}}}}:::: ccccaaaannnn''''tttt uuuunnnnlllliiiinnnnkkkk $$$$ffffiiiilllleeee:::: $$$$!!!!"""";;;;
  674.                 }}}}
  675.  
  676.  
  677.        CLEAR this
  678.             This method is triggered when the whole hash is to be
  679.             cleared, usually by assigning the empty list to it.
  680.  
  681.             In our example, that would remove all the user's
  682.             dotfiles!  It's such a dangerous thing that they'll
  683.             have to set CLOBBER to something higher than 1 to
  684.             make it happen.
  685.  
  686.                 ssssuuuubbbb CCCCLLLLEEEEAAAARRRR    {{{{
  687.                     ccccaaaarrrrpppp &&&&wwwwhhhhoooowwwwaaaassssiiii iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  688.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  689.                     ccccrrrrooooaaaakkkk """"@@@@{{{{[[[[&&&&wwwwhhhhoooowwwwaaaassssiiii]]]]}}}}:::: wwwwoooonnnn''''tttt rrrreeeemmmmoooovvvveeee aaaallllllll ddddoooottttffffiiiilllleeeessss ffffoooorrrr $$$$sssseeeellllffff---->>>>{{{{UUUUSSSSEEEERRRR}}}}""""
  690.                         uuuunnnnlllleeeessssssss $$$$sssseeeellllffff---->>>>{{{{CCCCLLLLOOOOBBBBBBBBEEEERRRR}}}} >>>> 1111;;;;
  691.                     mmmmyyyy $$$$ddddooootttt;;;;
  692.                     ffffoooorrrreeeeaaaacccchhhh $$$$ddddooootttt (((( kkkkeeeeyyyyssss %%%%{{{{$$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}}}}})))) {{{{
  693.                         $$$$sssseeeellllffff---->>>>DDDDEEEELLLLEEEETTTTEEEE(((($$$$ddddooootttt))));;;;
  694.                     }}}}
  695.                 }}}}
  696.  
  697.  
  698.        EXISTS this, key
  699.             This method is triggered when the user uses the
  700.             _e_x_i_s_t_s_(_) function on a particular hash.  In our
  701.             example, we'll look at the {{{{LLLLIIIISSSSTTTT}}}} hash element for
  702.             this:
  703.  
  704.                 ssssuuuubbbb EEEEXXXXIIIISSSSTTTTSSSS   {{{{
  705.                     ccccaaaarrrrpppp &&&&wwwwhhhhoooowwwwaaaassssiiii iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  706.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  707.                     mmmmyyyy $$$$ddddooootttt ==== sssshhhhiiiifffftttt;;;;
  708.                     rrrreeeettttuuuurrrrnnnn eeeexxxxiiiissssttttssss $$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}---->>>>{{{{$$$$ddddooootttt}}}};;;;
  709.                 }}}}
  710.  
  711.  
  712.        FIRSTKEY this
  713.             This method will be triggered when the user is going
  714.             to iterate through the hash, such as via a _k_e_y_s_(_) or
  715.             _e_a_c_h_(_) call.
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724. 12/Feb/96                perl 5.002 with                       11
  725.  
  726.  
  727.  
  728.  
  729.  
  730. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  731.  
  732.  
  733.                 ssssuuuubbbb FFFFIIIIRRRRSSSSTTTTKKKKEEEEYYYY {{{{
  734.                     ccccaaaarrrrpppp &&&&wwwwhhhhoooowwwwaaaassssiiii iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  735.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  736.                     mmmmyyyy $$$$aaaa ==== kkkkeeeeyyyyssss %%%%{{{{$$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}}}}};;;;          #### rrrreeeesssseeeetttt eeeeaaaacccchhhh(((()))) iiiitttteeeerrrraaaattttoooorrrr
  737.                     eeeeaaaacccchhhh %%%%{{{{$$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}}}}}}
  738.                 }}}}
  739.  
  740.  
  741.        NEXTKEY this, lastkey
  742.             This method gets triggered during a _k_e_y_s_(_) or _e_a_c_h_(_)
  743.             iteration.  It has a second argument which is the
  744.             last key that had been accessed.  This is useful if
  745.             you're carrying about ordering or calling the
  746.             iterator from more than one sequence, or not really
  747.             storing things in a hash anywhere.
  748.  
  749.             For our example, we our using a real hash so we'll
  750.             just do the simple thing, but we'll have to indirect
  751.             through the LIST field.
  752.  
  753.                 ssssuuuubbbb NNNNEEEEXXXXTTTTKKKKEEEEYYYY  {{{{
  754.                     ccccaaaarrrrpppp &&&&wwwwhhhhoooowwwwaaaassssiiii iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  755.                     mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  756.                     rrrreeeettttuuuurrrrnnnn eeeeaaaacccchhhh %%%%{{{{ $$$$sssseeeellllffff---->>>>{{{{LLLLIIIISSSSTTTT}}}} }}}}
  757.                 }}}}
  758.  
  759.  
  760.        DESTROY this
  761.             This method is triggered when a tied hash is about to
  762.             go out of scope.  You don't really need it unless
  763.             you're trying to add debugging or have auxiliary
  764.             state to clean up.  Here's a very simple function:
  765.  
  766.                 ssssuuuubbbb DDDDEEEESSSSTTTTRRRROOOOYYYY  {{{{
  767.                     ccccaaaarrrrpppp &&&&wwwwhhhhoooowwwwaaaassssiiii iiiiffff $$$$DDDDEEEEBBBBUUUUGGGG;;;;
  768.                 }}}}
  769.  
  770.  
  771.        Note that functions such as _k_e_y_s_(_) and _v_a_l_u_e_s_(_) may return
  772.        huge array values when used on large objects, like DBM
  773.        files.  You may prefer to use the _e_a_c_h_(_) function to
  774.        iterate over such.  Example:
  775.  
  776.            #### pppprrrriiiinnnntttt oooouuuutttt hhhhiiiissssttttoooorrrryyyy ffffiiiilllleeee ooooffffffffsssseeeettttssss
  777.            uuuusssseeee NNNNDDDDBBBBMMMM____FFFFiiiilllleeee;;;;
  778.            ttttiiiieeee((((%%%%HHHHIIIISSSSTTTT,,,, NNNNDDDDBBBBMMMM____FFFFiiiilllleeee,,,, ''''////uuuussssrrrr////lllliiiibbbb////nnnneeeewwwwssss////hhhhiiiissssttttoooorrrryyyy'''',,,, 1111,,,, 0000))));;;;
  779.            wwwwhhhhiiiilllleeee (((((((($$$$kkkkeeeeyyyy,,,,$$$$vvvvaaaallll)))) ==== eeeeaaaacccchhhh %%%%HHHHIIIISSSSTTTT)))) {{{{
  780.                pppprrrriiiinnnntttt $$$$kkkkeeeeyyyy,,,, '''' ==== '''',,,, uuuunnnnppppaaaacccckkkk((((''''LLLL'''',,,,$$$$vvvvaaaallll)))),,,, """"\\\\nnnn"""";;;;
  781.            }}}}
  782.            uuuunnnnttttiiiieeee((((%%%%HHHHIIIISSSSTTTT))));;;;
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790. 12/Feb/96                perl 5.002 with                       12
  791.  
  792.  
  793.  
  794.  
  795.  
  796. PERLTIE(1)     User Contributed Perl Documentation     PERLTIE(1)
  797.  
  798.  
  799.        TTTTyyyyiiiinnnngggg FFFFiiiilllleeeeHHHHaaaannnnddddlllleeeessss
  800.  
  801.        This isn't implemented yet.  Sorry; maybe someday.
  802.  
  803. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  804.        See the _D_B___F_i_l_e manpage or the _C_o_n_f_i_g manpage for some
  805.        interesting _t_i_e_(_) implementations.
  806.  
  807. BBBBUUUUGGGGSSSS
  808.        Tied arrays are _i_n_c_o_m_p_l_e_t_e.  They are also distinctly
  809.        lacking something for the $$$$####AAAARRRRRRRRAAAAYYYY access (which is hard,
  810.        as it's an lvalue), as well as the other obvious array
  811.        functions, like _p_u_s_h_(_), _p_o_p_(_), _s_h_i_f_t_(_), _u_n_s_h_i_f_t_(_), and
  812.        _s_p_l_i_c_e_(_).
  813.  
  814.        You cannot easily tie a multilevel data structure (such as
  815.        a hash of hashes) to a dbm file.  The first problem is
  816.        that all but GDBM and Berkeley DB have size limitations,
  817.        but beyond that, you also have problems with how
  818.        references are to be represented on disk.  One
  819.        experimental module that does attempt to partially address
  820.        this need is the MLDBM module.  Check your nearest CPAN
  821.        site as described in the _p_e_r_l_m_o_d manpage for source code
  822.        to MLDBM.
  823.  
  824. AAAAUUUUTTTTHHHHOOOORRRR
  825.        Tom Christiansen
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856. 12/Feb/96                perl 5.002 with                       13
  857.  
  858.  
  859.