in reply to Question about map function [ANSWERED]

You can perfectly sort "YYYY.MM.DD" values as strings with cmp. You don't need to strip dots. So the foreach loop doesn't needed at all.

Update: but if you want numeric than

my @records = map { $_->[0] } sort $sort_routine map { $_->{'date'} =~ /(\d+)\.(\d+)\.(\d+)/; [ $_ +, $_->{'title'}, $1.$2.$3 ] }

or shorter:

my @records = map { $_->[0] } sort $sort_routine map { [ $_, $_->{title}, join '', $_->{date} =~ /\d+/g ] }

Replies are listed 'Best First'.
Re: Question about map function [SOLVED!]
by automandc (Acolyte) on Nov 17, 2008 at 20:13 UTC
    Perfect! I do want to sort numerically, hence the need to remove the periods. I tried your second (shorter) solution and it works exactly as needed. I knew there was a way to do it with regexes, but needed superior wisdom to show me the way.

    Much thanks.

      If your months/days are 2-digit zero padded (as YYYY.MM.DD would indicate), then you don't need to sort numerically...alphabetically sorting is fine. Is the format, e.g., "2008.01.01" or "2008.1.1" ??