in reply to Comparing all keys in a hash
I have to say that I really wonder about this node and thread. The code is interesting in its own way, and the discussion below has some merit I suppose, but I can't help but question a bunch of things.
First off what does this routine do? It "compares" two hashes. Presumably the hashes are of numbers? Its a litte unclear if they are because sort keys %$h1 sorts them lexicographically. I think you want sort {$a <=> $b} keys %$h1.
Next is the issue of what you return. You return the difference in the number of elements if they are different, otherwise you return which of the two has a lower element encoded ala <=>. What I wonder is why? Why is a hash that contains a single key, say 100000 smaller than a hash with two keys, say 1,2? Why is a hash with keys (0,1,100,200) smaller than a hash with (0,2,2,2)?
If I saw this code in production without considerable explanation as to its use and relevance I would earmark it for a rewrite as being misconceived. Either it should be renamed, or it should be refactored, or it should be redone. It just doesnt make sense...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Comparing all keys in a hash
by rinceWind (Monsignor) on Mar 21, 2003 at 10:00 UTC | |
by demerphq (Chancellor) on Mar 21, 2003 at 14:54 UTC | |
|
Re: Re: Comparing all keys in a hash
by shotgunefx (Parson) on Mar 21, 2003 at 10:10 UTC |