- or download this
@data = (
'buy 1/23/01 100 12.625 50 25.25',
...
'buy 10/23/01 100 12.625 50 25.25',
'buy 10/25/01 100 12.625 50 25.25',
);
- or download this
sub get_date {
my $string = shift;
my $date = (split ' ', $string)[1]; # second field
return $date;
- or download this
for $line (@data) {
push @dates, get_date($line);
}
- or download this
for $line (@data) {
push @dates, [ get_date($line), $line ];
}
- or download this
sub get_date {
my $string = shift;
...
my ($d, $m, $y) = split '/', $date;
return sprintf "%02d%02d%02d", $y, $m, $d;
}
- or download this
@dates = sort { $a->[0] <=> $b->[0] } @dates;
- or download this
@data = map $_->[1], @dates;
- or download this
@data =
restore(
sort { $a->[0] <=> $b->[0] }
extract(@data)
);
- or download this
# extract(@data)
# becomes
map [ get_date($_), $_ ], @data
- or download this
# restore(...)
# becomes
map $_->[1], ...
- or download this
@data =
map $_->[1],
sort { $a->[0] <=> $b->[0] }
map [ get_date($_), $_ ],
@data;
- or download this
@data =
map { restore($_) }
sort { ... }
map { extract($_) }
@data;