Re: Tie::Hash::Regex vs Tie::RegexpHash

2001-05-26 Thread Marcel Grunauer

On Friday, May 25, 2001, at 03:18  PM, Cross David - dcross wrote:

 It's all very clever, but I'm not convinced how useful it is.

Since when has that ever stopped us?

Marcel

--
$ perl -we time
Useless use of time in void context at -e line 1.



Tie::Hash::Regex vs Tie::RegexpHash

2001-05-25 Thread Cross David - dcross


I was just looking thru CPAN (and, yes, I realise I should have done that
_before_ writing T::H::R[1]) and I found a module called Tie::RegexpHash.
Having looked at it in some detail, I see it's doing the opposite of T::H::R
and I think that's quite interesting.

In T::H::R, the keys are always strings. Just as they are in 'real' hashes.
The only clever bits (and therefore the only bits I had to override from
Tie::StdHash) are when you're looking up a key - FETCH, EXISTS and DELETE.
If your key doesn't match an existing key, then it's used as a regex and we
see if that regex matches any of the existing keys.

In T::R, the keys that you use in the hash are all treated as regexes. In
effect you're saying if you look up a value using a key that matches this
regex, then return this value. An added complication is that the key/value
pairs are _ordered_ (the underlying object is an array, not a hash) so that
you can guarantee that the regexes are checked in the same order as you
added them to the hash.

It's all very clever, but I'm not convinced how useful it is[2]. And it took
a whole bunch more implementation than T::H::R did. Oh, and it's written for
Perl 5.6, but the only reason I can see is so the author can 'use warnings'.

Anyway, just thought someone might be interested :)

Dave...

[1] Hmmm... note to self - see if you can come up with a tied hash that
abbreviates to T::H::C.

[2] Not that I'm one to complain about _that_ - people in glass houses...

-- 


The information contained in this communication is
confidential, is intended only for the use of the recipient
named above, and may be legally privileged. If the reader 
of this message is not the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  
If you have received this communication in error, please 
re-send this communication to the sender and delete the 
original message or any copy of it from your computer
system.



Re: Tie::Hash::Regex vs Tie::RegexpHash

2001-05-25 Thread Steve Keay

 In T::R, the keys that you use in the hash are all treated as regexes. In
 effect you're saying if you look up a value using a key that matches this
 regex, then return this value. An added complication is that the key/value
 pairs are _ordered_ (the underlying object is an array, not a hash) so that
 you can guarantee that the regexes are checked in the same order as you
 added them to the hash.
 
 It's all very clever, but I'm not convinced how useful it is[2]. And it took
 a whole bunch more implementation than T::H::R did. Oh, and it's written for
 Perl 5.6, but the only reason I can see is so the author can 'use warnings'.

I have wrote something in 1997 that needed exactly this (although I
never dreamed of looking at CPAN for a module to do something so
simple):

I need to do a whois lookup for a domain name.  Different domain
names need to be looked up on different whois servers.  So I have a
list of domains and their relevant whois server, like: co.uk =
whois.nic.uk.  So I can look for, e.g., test.co.uk in the list and
know that I need to query whois.nic.uk for info about that domain.

--
sigs are for whimps



Re: Tie::Hash::Regex vs Tie::RegexpHash

2001-05-25 Thread Chris Devers

At 02:18 PM 2001.05.25 +0100, Dave Cross wrote:
[1] Hmmm... note to self - see if you can come up 
with a tied hash that abbreviates to T::H::C.

Semi-plausible: Tie::Hash::Complex
Not-plausible: Tie::Hash::Cannabis

Might see the light of day?: Tie::Hash::Conway




--
Chris Devers [EMAIL PROTECTED]




Re: Tie::Hash::Regex vs Tie::RegexpHash

2001-05-25 Thread Piers Cawley

Chris Devers [EMAIL PROTECTED] writes:

 At 02:18 PM 2001.05.25 +0100, Dave Cross wrote:
 [1] Hmmm... note to self - see if you can come up 
 with a tied hash that abbreviates to T::H::C.
 
 Semi-plausible: Tie::Hash::Complex
 Not-plausible: Tie::Hash::Cannabis
 
 Might see the light of day?: Tie::Hash::Conway

Presumably this will lead to a load of gags about not wanting to go
too far from his stash?

-- 
Piers Cawley
www.iterative-software.com