Howdy Monks from Texas,
I have a problem and since I ain't the brightest star in the night sky I thought I would ask for a little help. I have a webpage that displays the following data. This is a text representation, not the pretty output of the page:
Transid | Date | Time | PagerID | Message Description 99996 | Feb10 | 11:18 | sundallas_e | dspmmr3 at 02/10/2005 10:18:04 +CPU Utilization is at 99.73% 99995 | Feb10 | 11:17 | hpdallas_e | zcompass at 02/10/2005 09:57:04 + CPU Utilization is at 100%
And so forth, the problem I have is with my sort. At any given time I have 200 messages displaying. I sort numerically descending the array to make sure the list displays numerically with the highest value for the Transid at the top. The problem is that once I reach 99999 and roll-over to 00001, the 00001 event displays at the bottom of the list and of course until 200 events occur after this roll-over the page is out of whack. I keep trying to think of exactly what I need to do with additional code at the sort and try fixing this myself, but I have mental block and can't seem to figure it out. Below is the actual code that performs the sorting. Any and all suggestions would be greatly appreciated.
Thanks, Danny
### Output Loop. Sub Routine to generate Web Output to ActiveWindow sub webpage_output { while(1) { if ( -e $Statfile ){ open(ACTWIN,">$ActiveWindow") || die "Couldn't open fi +le $ActiveWindow - $!\n"; print ACTWIN "Transid|Datestamp|Timestamp|Ticket|Pager +Id|Message|Status\n"; ### ### changed method of opening getting the last files in the directory ### also changed sort order to display on screen ### April 5, 2004 opendir(CacheDir,$Cache) || die "Couldn't open the dir +ectory $Cache: $!\n"; @filelist=grep { /[0-9]{5}/ } readdir(CacheDir); closedir(CacheDir); @sortlist=sort {$b <=> $a} @filelist; for ($i=0;$i<$MsgCount;$i++) { $filename=$sortlist[$i]; if ($filename) { open(ITEM,"$Cache/$filename"); while(<ITEM>){ chomp; if(/TransID=(.*)/){$a=$1;} if(/DATE=(.*)/){$b=$1;} if(/TIME=(.*)/){$c=$1;} if(/TICKET=(.*)/){$d=$1;} if(/PagerID=(.*)/){$e=$1;} if(/Message=(.*)/) { $f=$1; $cont="Y"; next; } if(/Status=(.*)/){$g=$ +1; $cont="";next;} if ($cont eq "Y") { $f=$f.$_; } } close(ITEM); print ACTWIN "$a|$b|$c|$d|$e|$f|$g\n"; } } close(ACTWIN); unlink($Statfile) || die "Couldn't delete $Statfile - +$!\n"; } sleep($naptime); } }

20050110 Edit by ysth: code tags around sample data

20050212 Edit by castaway: Changed title from 'sort a nuts'


In reply to Sorting through a rollover by onegative

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.