I have made a perl script that sorts through a hotline log, grabs the name of the file that was downloaded, writes the name to the key of a hash, then writes the count to the hash value.
When it's done counting, the script then generates the start of an html page and a table. Inside that, the script loops through the values and keys spitting out the necessary <tr> tags. Finally, it closes the table and closes the html tags. Below is just the loop from my script that generates the individual table entries. (I had to take out a lot of the HTML tags so it would be accepted.)
foreach $key (sort {$freqpage{$b} <=> $freqpage{$a}} keys %freqpage)
{
print HOTFILES "$freqpage{$key}\n";
print HOTFILES "$key \n";
}
Everything works great except when it's done I have an HTML page with ~1800 table entries. I'd like to trim this list down to just the top 20 files downloaded instead of a 900k download/redraw hell page.
How do I limit foreach? I think using a while() or for() wouldn't work because one iteration would still trigger the aforementioned foreach() loop that would *then* go through all the files. I'm out of ideas. Anyone have a suggestion?
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.