sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:
To yield:my %values = ( "apple" => "1", "pear" => "3", "orange" => "3", "melon" => "2", "grape" => "2");
Kutsu tried to help with the code on his pad. The idea was to use HOA or AOAs and I haven't any experience with those (or references) so I'm kind of lost. What I have to play with isLevel 3: Pear, Orange Level 2: Melon, Grape Level 1: apple
Which works. The problem I am having is trying to figure out how this would work with dynamic data. I'll never know what "levels" exist or how many there are, so using indexes probably won't work properly.my %hash = ( 1 => ["apple"], 2 => ["melon", "grape"], 3 => ["pear", "orange"] ); $hash{1}[1] = "pickle"; print "Level $_\n@{$hash{$_}}\n\n" for reverse sort keys %hash;
In the end, I need to be able to sort and rip parts and pieces of this with ease (like a typical hash). Things to keep in mind are; I need to be able to sort by length of characters in the words, and find specific elements which words start with (or end with) specific characters. Ideally, it'd need to be as maintainable as a hash which I'm sure HOAs and AOAs are capable of.
I'm just new to the multidimensional world and could use some insight.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting hashes with new value detection
by Roy Johnson (Monsignor) on Jan 24, 2006 at 17:43 UTC | |
Re: Sorting hashes with new value detection
by kutsu (Priest) on Jan 24, 2006 at 18:00 UTC | |
Re: Sorting hashes with new value detection
by serf (Chaplain) on Jan 24, 2006 at 18:25 UTC | |
Re: Sorting hashes with new value detection
by Aristotle (Chancellor) on Jan 24, 2006 at 17:52 UTC | |
by sulfericacid (Deacon) on Jan 24, 2006 at 17:57 UTC | |
by Aristotle (Chancellor) on Jan 24, 2006 at 18:15 UTC | |
by thundergnat (Deacon) on Jan 24, 2006 at 20:30 UTC |