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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|