Beefy Boxes and Bandwidth Generously Provided by pair Networks
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
in thread Tied Variables - why? by samurai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found