I have an issue with doing a sort in a memory buffer as follows. I'm not sure
1. How to do this ?
and 2. What the most efficient method is ?
The input file looks something like this (I can't change the format of this file)
a 0 f g j k
b 4 y h t e e e
c 1 n s v c x
d 3 f f f
I've written a bit of code to produce an HTML page for use with MIME::Lite. This all works fine except that I need to be able to sort the contents based on the second field (descending) in each row. Not the first which is the format the file is presented to me in.
This is the code I have to create the HTML page from the input file
my $buffer;
open (INPF,"<input.dat") or die "Can't open input.dat: $!\n";
while (<INPF>) {
m/^(\w+)\s+(\d+)\s+(\w+)(.*)$/ or die "Unable to match any lines:
+$!\n";
if ($2 < 90) { $buffer .= "<tr bgcolor='#00FF00'><td>$1</td><td>$
+2</td><td>$3</td><td>$4</td></tr>\n";
} elsif ($2 < 180) {
$buffer .= "<tr bgcolor='#FF6600'><td>$1</td><td>$2</td><td>$3
+</td><td>$4</td></tr>\n";
} else {
$buffer .= "<tr bgcolor='#FF0000'><td>$1</td><td>$2</td><td>$3
+</td><td>$4</td></tr>\n";
}
}
close INPF;
How do I sort the resulting buffer on field 2 before passing it on to the mail routine ?
I should point out that the input file is unlikely to grow beyond about 30,000 records (approx 20Mb)
Any help appreciated
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.