#!/usr/bin/perl -w
use strict;
use warnings;
my %the_hash = (
'log1.log' => '11/01/2001',
'log2.log' => '11/02/2001',
'floppy-earred.dog' => '01/02/1999',
'log600.log' => '09/05/2003',
);
my( @sortedkeys, %sortedlbls );
use CGI;
$| = 1;
my $q = CGI->new();
print $q->header,
$q->start_html('Test for waxmop'),
$q->h1('Test checkbox_group'),
$q->start_form;
# Sort by the keys (filenames), display "filename date"
@sortedkeys = sort keys %the_hash;
%sortedlbls = map { $_ , "$_ $the_hash{$_}" } @sortedkeys;
print $q->checkbox_group(
-name => 'byfilename',
-values => [ @sortedkeys ],
-labels => { %sortedlbls },
-linebreak => 1
);
print "
\n";
# Sort by the values (date strings), display "date filename"
@sortedkeys = sort { $the_hash{$a} cmp $the_hash{$b} } keys %the_hash;
%sortedlbls = map { $_ , "$the_hash{$_} $_" } @sortedkeys;
print $q->checkbox_group(
-name => 'bydatestring',
-values => [ @sortedkeys ],
-labels => { %sortedlbls },
-linebreak => 1
);
print "
\n";
# Sort by the 'real' date value using Schwartzian transform
@sortedkeys = map { $_->[0] } # get back our saved key
sort { $a->[3] <=> $b->[3] # sort by year
||
$a->[1] <=> $b->[1] # then by month
||
$a->[2] <=> $b->[2] # then by day of month
}
map { # make a temporary list of arrays, with each
[ $_, # array's first element the original key
# and the next three elements the date
$the_hash{$_} =~ m!^(\d\d)/(\d\d)/(\d\d\d\d)$!
# string pieces mm dd yyyy
]
}
keys %the_hash;
%sortedlbls = map { $_ , "$the_hash{$_} $_" } @sortedkeys;
print $q->checkbox_group(
-name => 'bydatevalue',
-values => [ @sortedkeys ],
-labels => { %sortedlbls },
-linebreak => 1
);
print "
\n";
print $q->endform;
print $q->end_html;