onegative has asked for the wisdom of the Perl Monks concerning the following question:
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.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%
### 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'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting through a rollover
by fglock (Vicar) on Feb 10, 2005 at 17:38 UTC | |
by RazorbladeBidet (Friar) on Feb 10, 2005 at 17:56 UTC | |
by Roy Johnson (Monsignor) on Feb 10, 2005 at 20:30 UTC | |
by RazorbladeBidet (Friar) on Feb 10, 2005 at 20:40 UTC | |
|
Re: Sorting through a rollover
by trammell (Priest) on Feb 10, 2005 at 19:20 UTC | |
by onegative (Scribe) on Feb 10, 2005 at 19:37 UTC | |
by onegative (Scribe) on Feb 11, 2005 at 13:52 UTC | |
by onegative (Scribe) on Feb 11, 2005 at 19:56 UTC | |
|
Re: Sorting through a rollover
by ikegami (Patriarch) on Feb 10, 2005 at 18:56 UTC | |
|
Re: Sorting through a rollover
by phaylon (Curate) on Feb 10, 2005 at 17:10 UTC | |
by onegative (Scribe) on Feb 10, 2005 at 17:20 UTC | |
by phaylon (Curate) on Feb 10, 2005 at 17:55 UTC | |
by phaylon (Curate) on Feb 10, 2005 at 19:05 UTC | |
|
Re: Sorting through a rollover
by RazorbladeBidet (Friar) on Feb 10, 2005 at 17:07 UTC |