Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.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
How do I sort the resulting buffer on field 2 before passing it on to the mail routine ?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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: most efficient buffer sort
by GrandFather (Saint) on Dec 14, 2005 at 11:09 UTC | |
| |
|
Re: most efficient buffer sort
by salva (Canon) on Dec 14, 2005 at 11:55 UTC | |
by Anonymous Monk on Dec 14, 2005 at 12:33 UTC | |
by salva (Canon) on Dec 14, 2005 at 12:54 UTC | |
by Anonymous Monk on Dec 14, 2005 at 12:58 UTC | |
|
Re: most efficient buffer sort
by serf (Chaplain) on Dec 14, 2005 at 12:15 UTC | |
by salva (Canon) on Dec 14, 2005 at 13:06 UTC | |
by Anonymous Monk on Dec 14, 2005 at 12:36 UTC |