Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
According to perltie: The tie() function binds a variable to a class (package) that will provide the implementation for access methods for that variable. Once this magic has been performed, accessing a tied variable automatically triggers method calls in the proper class. The complexity of the class is hidden behind magic methods calls. Basically, tie() is used to make a complex system of functions a simple scalar or hash.
What this comes down to, and the reason I use perltie often is because tying to a scalar or a hash is functioning as a way to limit the complexity a user has to deal with, and at times a tied value may just seem intuitive. A good example in both cases is Apache::Session. The interface to Apache::Session is very simple: tie a hash to the desired class and use the hash as normal. It's much simpler for a user to just modify a hash value, and let Apache::Session do the real work, than it would be otherwise. A hash seems much more intuitive, and simpler to manipulate than an object that may be messed around with, or a user misusing subroutines. There is *no* way for a user to mess up, when using Apache::Session. Another example would be lots of data manipulation drivers/modules, such as Tie::File, and DB_File. Hash provide organization for our data, and tied hashes just seem to be perfect for retrieval and insertation of data. There are probably countless other examples, as well, where a tied file just *feels* right, and in perl TM..... means we can do things in our own style, which may very well be tie() :) Hope that helps, but if you still don't believe tied variables are any help, I'd advise you to read this article, if you want a more detailed explanation by a better coder. Gyan Kapur gyan.kapur@rhhllp.com In reply to Re: Tied Variables - why?
by Revelation
|
|