"Christoph Rippel" <crippel / primenet.com> wrote:
>
> > -----Original Message-----
> > From: Ben Tilly [mailto:ben_tilly / hotmail.com]
> > Sent: Sunday, January 07, 2001 10:04 PM
> > To: ruby-talk ML
> > Subject: [ruby-talk:8822] Re: No :<, :>, etc. methods for Array
> > I have mentioned before, perhaps I should mention again.
> >
> > The right container modules would (when combined with
> > mix-ins) provide a complete equivalent to Perl's tie.
>Since I am pretty about ignorant about Perl (among many
>other things) what is a good pointer to ``Perl's tie''?
>(I confess I was thinking more along the lines of the
>C++-STL or the Java Container classes.)
>
If you have Perl installed the following commands will
tell you more about tie:

  perldoc -f tie
  perldoc perltie
  perldoc AnyDBM_File

And if you also have Berkeley DB installed then:

  perldoc DB_File

It is a very handy interface to use in a lot of scripting
problems.  And it looks very impressive.  But in fact all
that the Perl folks did is allow a class that provides a
few basic methods to have native datatypes "tied" to it,
and Perl simulates all of the native stuff by making the
appropriate method calls.

Since Perl's type system is implemented in its syntax,
this cannot be duplicated without direct language support.
But most of Ruby's type system is implemented in its OO
structure and the syntax of how you access an array, hash,
and even call anonymous functions is the same.  So Ruby
would get equivalent flexibility by having a series of
well thought-out modules (similar to Enumerable) which
would allow someone to get a drop-in replacement for the
native data-types without having to write most of the
interface themselves.

For the record the biggest use of tie in Perl is accessing
dbm files.  The full interface (much of which is optional)
involves writing the following methods:

  TIEHASH
  FETCH
  STORE
  EXISTS
  DELETE
  CLEAR
  FIRSTKEY
  NEXTKEY
  DESTROY

If you write those (or as many as you will be needing) then
you can make virtually anything look like a hash.

Cheers,
Ben
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com