in reply to epoch reduction
use List::Util qw( max ); use POSIX qw( strftime ); my %by_date; for my $time (@times) { my $date = strftime('%Y-%m-%d', localtime($time)); $by_date{$date} = max($by_date{$date}||0, $time); } my @filtered_times = map $by_date{$_}, sort keys(%by_date);
One second thought, the following seems better, especially if the initial list of times is already sorted.
use POSIX qw( strftime ); my $last_date = ''; my @filtered_times; for my $time (sort { $a <=> $b } @times) { my $date = strftime('%Y-%m-%d', localtime($time)); if ($date eq $last_date) { $filtered_times[-1] = $time; } else { push @filtered_times, $time; $last_date = $date; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: epoch reduction
by Marshall (Canon) on Apr 20, 2012 at 02:38 UTC | |
by ikegami (Patriarch) on Apr 20, 2012 at 16:36 UTC | |
by Marshall (Canon) on Apr 22, 2012 at 08:06 UTC |