Hi,
You might want to look at
Text::CSV for parsing your csv file. It could make things a bit simpler.
And then, as McDarren says, Date::Calc would be quite helpful for your sort. Perhaps convert it to a unixtime format and then perform the sort.
A sort sub to get the job done:
# Store your values in a hash of hashes
# $kols{line1} = { date => 12-12-06, bits => 12, ... }
my $orderby = "date" # or "bits, ..."
my $updown = "DESC" # or "ASC"
foreach (sort { &mysort($updown) } keys %kols) {
} # end-foreach
sub mysort {
my ($direction) = @_;
if ($direction eq "DESC") {
$kols{$b}{$orderby} <=> $kols{$a}{$orderby}
||
$kols{$b}{$orderby} cmp $kols{$a}{$orderby}
} # end-if
else {
$kols{$a}{$orderby} <=> $kols{$b}{$orderby}
||
$kols{$a}{$orderby} cmp $kols{$b}{$orderby}
} # end-else
} # end-sub
Cheers.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.