Thanks Japhy...
I can see where you are going with this, we convert the month into a number, and then
sort the dates as a string.
My dates are the second keys of a hash of hashes. So I have routine like:
foreach $firstkey (keys %hoh)
{
foreach $thedate (keys %{ $hoh { $firstkey }} )
{
#do stuff with what we find there
}
}
What I don't quite get is how I integrate the sort into what I am already doing. If I
just wanted to sort the keys as is, I could insert sort( before (keys above.
But I need to process the date before sorting on it, and I can't see how to get it
into the loop. Or perhaps I shouldn't.
Can you help further?
Thanks,
Paul.
In reply-to [EMAIL PROTECTED] on Tue Jul 3 15:59:15 2001
>On Jul 3, [EMAIL PROTECTED] said:
>
>>My hash has keys that are dates in "ddmmmyyyy" format (21Jul2001).
>
>The date format DDMMYYYY is easily sortable (even via normal 'cmp'
>comparison). Translate your dates into this format:
>
> %mon2num = qw(
> Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06
> Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12
> );
>
> %num2mon = reverse %mon2num; # so we can go backwards, if desired
>
> @sorted_dates =
> map { s/(\d\d)(\d\d)/$1$num2mon{$2}/; $_ } # change MM -> MON
> sort # sort the dates
> map { s/(\D+)/$mon2num{$1}/; $_ } # change MON -> MM
> @dates;
>
>This is a Guttman-Rosler Transform (it might look like a Schwartzian
>Transform, but it is not). The GRT works by finessing the data into a
>form that can be sorted by simply saying sort(), and then finessing it
>back to how you want.
>
>This assumes your dates are DDMMMYYYY. If you have a DMMMYYYY (like
>2Jul2001), you'll need to pad it with a 0.
>
>--
>Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
>I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
>Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
>Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
>Acacia Fraternity, Rensselaer Chapter. Brother #734
>** Manning Publications, Co, is publishing my Perl Regex book **
>
>
------------------------------------------------
Global WebMail -
Delivered by Global Internet www.global.net.uk
------------------------------------------------