in reply to How to compare hash value
I'm not sure what you mean when you say you want to group the arrays together. Are you adding a new hash entry, pushing them on an array somewhere?
Since I don't understand your grouping, I'll just tackle the other part of your question. One way to compare arrays would be to create a "stringify" function:
# note that having a sub for this is overkill, but if you # need more functionality, it's easy to encapsulate here (such # as making it case-insensitive to independant of order) sub stringify { local $" = ""; return "@{$_[0]}" } if (stringify([sort @array1]) eq stringify([sort @array2])) { # arrays are the same }
At that point, to find all keys that have identical values:
my %matches; while (my ($key,$value) = each %somehash) { # stringified arrays as keys push @{$matches{stringify([sort @$value])}} => $key; }
The above code snippet probably doesn't do what you want, but it might give you a starting point. Each stringified array will now point to a list of keys that match it.
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to compare hash value
by Jasper (Chaplain) on Apr 23, 2003 at 14:21 UTC | |
by Ovid (Cardinal) on Apr 23, 2003 at 14:23 UTC | |
by nothingmuch (Priest) on Apr 23, 2003 at 14:29 UTC |