Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: need to sort array of hash

by dsheroh (Prior)
on Dec 23, 2018 at 11:54 UTC ( #1227635=note: print w/replies, xml ) Need Help??

in reply to Re: need to sort array of hash
in thread need to sort array of hash

Note: Using the first (and only) element of values avoids the problem with not knowing the name of the key.
...but that only applies to the given sample data because the intermediate-level hash only contains a single key/value pair. If there are multiple keys/values in those hashes, you're screwed because values will return the values in a random order. (But the order is stable within a single run of the program, so long as the hash isn't modified, so at least it shouldn't throw sort into an infinite loop. You'll just potentially get results sorted on the wrong sub-hash.)

Replies are listed 'Best First'.
Re^3: need to sort array of hash
by BillKSmith (Prior) on Dec 24, 2018 at 02:31 UTC
    If there were more key/value pairs in the intermediate-level hash, we would need additional specifications to tell us which one to use in the sort. You have provided a detailed explanation of why this design could not meet such a requirement. (I am not even sure it could be modified to do so.) Even if the recommended redesign of the data structure could not be justified for current structure, one more requirement should surely tip the balance.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1227635]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-05-24 23:42 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (142 votes). Check out past polls.