instead ofmy @records = map { $_->[0] } sort $sort_routine map { [ $_, $_->{'title'}, $_->{'cleandate'} ] } @_;
my @records = sort $sort_routine @_;
You're slowing things down and wasting memory.
Also,
($opt_g =~ /^t/i) ? #flag setting sort order ($sort_routine = \&sort_by_title) : ($sort_routine = \&sort_by_date);
is a complicated way of doing
$sort_routine = ( $opt_g =~ /^t/i ? \&sort_by_title : \&sort_by_date );
I've never seen a situation where it made sense to use an assignment inside of the conditional operator (?:).
So, if your date format is really YYYY.MM.DD (and not YYYY.M.D), you get
sub sort_records { my $sort_routine ( $opt_g =~ /^t/i ? sub { $a->{title} cmp $b->{title} } : sub { $a->{date} cmp $b->{date} } ); return sort $sort_routine @_; }
In reply to Re: Question about map function [ANSWERED]
by ikegami
in thread Question about map function [ANSWERED]
by automandc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |