Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a hash whose value is an anonymous array
#key => id,start,end %hash ={ key1 => id1,2009/07/20-12-00-00-00,2009/07/20-15- + 00-00 key1 => id2,2009/07/20-15-10-00, key2 => id1,2009/07/21-12-00-00-00, };
in such scenario i wanted id with has the end date come first. How can i sort the anonymous array?

Replies are listed 'Best First'.
Re: sort hash values which is an array
by moritz (Cardinal) on Jul 21, 2009 at 13:28 UTC
    If you write %hash = { ... } the outcome will not be what you expect. use strict: use warnings will guard you against such mistakes.

    Use (...) instead of {...}.

Re: sort hash values which is an array
by JavaFan (Canon) on Jul 21, 2009 at 12:56 UTC
    Well, how to sort on an array element is a FAQ. But judging from you example, giving you the FAQ answer will just cause you to come with a followup question, as your example only has one array which actually has an end date, and a poorly formatted one as well. Note BTW, that your example isn't valid code. It misses quotes, and arrayref delimiters.

    I'd say, either read the FAQ, or format your real question.

Re: sort hash values which is an array
by Anonymous Monk on Jul 21, 2009 at 12:59 UTC
    in such scenario i wanted id with has the end date come first. How can i sort the anonymous array?

    First you need some valid perl. Please fix your code, its only 4 lines, and almost every line is an error.Try again please.