Why use Tie::Hash? 
Author Message
 Why use Tie::Hash?

So I'm getting ready to write a new object intended to be used with tie to
create a tied hash, and I see that Tie::Hash is part of the standard
distribution.  However, after looking at the code, I don't understand
quite what its purpose is.  Is there any reason why I should be inheriting
from Tie::Hash rather than just writing my own class from scratch?

It seems like all Tie::Hash gives me are error messages for things I
haven't implemented and an implementation of CLEAR that's considerably
less efficient than what I'd be able to manage.

Am I losing anything important by not inheriting from it?

--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker





Fri, 29 Sep 2000 03:00:00 GMT  
 Why use Tie::Hash?

Quote:

> So I'm getting ready to write a new object intended to be used with tie to
> create a tied hash, and I see that Tie::Hash is part of the standard
> distribution.  However, after looking at the code, I don't understand
> quite what its purpose is.  Is there any reason why I should be inheriting
> from Tie::Hash rather than just writing my own class from scratch?
> It seems like all Tie::Hash gives me are error messages for things I
> haven't implemented and an implementation of CLEAR that's considerably
> less efficient than what I'd be able to manage.
> Am I losing anything important by not inheriting from it?

Nothing except correct default handling for the methods you don't choose
to implement. If you use Tie::Hash you can even implement a simple tied

if TIEHASH is not defined).

--
Mike Heins                          http://www.minivend.com/  ___
                                    Internet Robotics        |_ _|____
There ain't nothin' in this world   131 Willow Lane, Floor 2  | ||  _ \
that's worth being a snot over.     Oxford, OH  45056         | || |_) |

                                    513.523.7621 FAX 7501        |_| \_\



Fri, 29 Sep 2000 03:00:00 GMT  
 Why use Tie::Hash?

Quote:

> I had the same question myself, except in this case its lynx and LWP,
> for most of my purposes, the only thing LWP gives me over lynx is error
> trapping.
> Wait, this makes too much sense, someone correct me.

Saves you a fork.  Saves you from being dependent on an external binary
(instead, you're dependent on an external module -- one or the other may
be better in different circumstances).  Gives you more leverage to play
with the internals if you need to do something more complicated later.  A
complicated LWP script won't port to lynx; a script using lynx will port
somewhat easily to using LWP.  Gives you error trapping, which is somewhat
important.  :)  Lets you get the information directly rather than having
to capture command output (and deal with possible broken pipes or tmp
files or what have you).

--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker





Fri, 29 Sep 2000 03:00:00 GMT  
 Why use Tie::Hash?

Flexibility, of course. Say you need to get the images; you can't
ask lynx to get them. Say you need to save them as they come: plug
something into the HTTP::Request (or wherever). Say you need to change
the browser identification string, I guess you can't do that with lynx
despite its huge array of command-line options. Say you need to write
a robot and respect robot rules; I don't know if lynx has it but you
certainly can add it to a module if it's missing.

A Big browser like netscape has a plug-in mechanism to allow you to
add functionality; lynx doesn't. But a Big browser also has tons of
functionality that may be irrelevant to your app. It's easy to have
exactly what you need with modules.



Sat, 30 Sep 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Tie hash of hash using MLDBM

2. using IPC::Shareable and using Tie::IxHash for the same hash

3. bizarre(?) problem, tied hash of tied hashes

4. What is tie used for and why

5. design considerations for using DB_File tie hashes ???

6. need to lock a tied hash using DB_File ?

7. Making hashes case insensitive using tie

8. Extension using tied hash

9. using flock() on a tied hash?

10. Using a tied hash as a class member - please help

11. Using exists() on a tie'd DB_File hash

12. using Tie::IxHash with nested hash tables

 

 
Powered by phpBB® Forum Software