automandc has asked for the wisdom of the Perl Monks concerning the following question:
(The sort_by_title and sort_by_date subs are basic sort functions straight from the perl cookbook. Only difference is the order in which they compare the fields).sub sort_records { my $sort_routine; ($opt_g =~ /^t/i) ? #flag setting sort order ($sort_routine = \&sort_by_title) : ($sort_routine = \&sort_by_date); foreach (@_) { ($_->{'cleandate'} = $_->{'date'}) =~ s/\D//g; } #do I need this? my @records = map { $_->[0] } sort $sort_routine map { [ $_, $_->{'title'}, $_->{'cleandate'} ] } # or can I do it here? @_; return @records; }
So my question is, can I get rid of the "foreach" loop and somehow do the same thing right in the map, but without changing the values in the source?
(Any other critiques/suggestions also welcome).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question about map function [ANSWERED]
by ikegami (Patriarch) on Nov 17, 2008 at 22:17 UTC | |
by automandc (Acolyte) on Nov 19, 2008 at 03:13 UTC | |
|
Re: Question about map function
by ccn (Vicar) on Nov 17, 2008 at 19:45 UTC | |
by automandc (Acolyte) on Nov 17, 2008 at 20:13 UTC | |
by runrig (Abbot) on Nov 17, 2008 at 20:36 UTC |