Sharon writes ..
>I should have clarified the format of my date. (sorry) It is text
>stored as mm-dd-yyyy.
>
>I should've also included a bigger picture too in retrospect...altho' I
>think what you've sent will get me going :)
>
><<<Bigger Picture, FYI The ultimate end goal is the user queries and
>sorts data by a variety of fields. The snippet I gave you was grabbing
>records to match their query criteria, then I needed to sort, not
>necessarily on the ordernumber (of course, that'd have been too easy :)
>).
>
>My inner hash has many more fields, both text and numeric. I will build
>a case of several maps or byordernums, to encompass both text and
>numeric sorting syntax depending on what they've picked.>>>
Ok, take a look at having a bunch of predefined subs stored in a lookup
hash with the keys as the sort field names that will be passed in via
the CGI. You could make the subs generate the list of keys based on
their specific sorting details. Eg:
my %sort_sub;
# we use the fact that yyyymmdd can be sorted in numerical order and
will
# provide a reliable date sort for mm-dd-yyyy dates
$sort_sub{date} = sub {
map { $_->[1] } # retrieve the key from the anonymous array
sort { $a->[0] <=> $b->[0] } # simple sort on the munged date
map { my($m,$d,$y) = split /-/, $_[0]->{$_}{date}; # munge the date
[ sprintf(%04d%02d%02d,$y,$m,$d), $_ ] # create the anonymous
array
}
keys %{$_[0]};
};
# simple numerical sort
$sort_sub{ordernumber} = sub { sort { $a <=> $b } keys %{$_[0]} };
# ... etc.
# then you'd do something like this for your output
my $sort_field = $cgi->param('sort_field');
for my $key ( $sort_sub{$sort_field}->(\%hash) )
{
print "$hash{$key}{name}\n"; # whatever output field you want
}
--
Jason King
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs