Lists
Bob Forgey
rforgey at alumni.caltech.edu
Thu May 25 20:57:36 CDT 2000
~sdpm~
Two ways, seems to me:
1) Reorder the date to go from most signficant to least significant
(don't forget to zero pad the days and months):
5/25/2000 -> 2000/05/25
then append the time (already in this format), and then alphabetically
sort:
2000/05/25:17:28:37 HostA 2250.16 2136.20 0 0
2000/05/25:17:28:52 HostB 905.77 928.76 0 0
2000/05/25:17:29:11 HostC 3632.60 3300.78 0 0
2000/05/25:18:28:37 HostA 2250.16 2136.20 0 0
2000/05/25:18:28:52 HostB 905.77 928.76 0 0
2000/05/25:18:29:11 HostC 3632.60 3300.78 0 0
See below for an example. Then undo the transformation to make it
pretty again.
2) Use Time::Local.pm to convert the date/time to time in seconds,
then sort numerically. Use localtime() to reverse the transformation.
Bob
>>>>> "Steve" == Steve Meier <smeier at sdsc.edu> writes:
Steve> Hey all,
Steve> Could anyone tell me what the easiest way to sort through this list
Steve> would be. What I have is a log file that looks like this:
Steve> 5/25/2000 17:28:37 HostA 2250.16 2136.20 0 0
Steve> 5/25/2000 17:28:52 HostB 905.77 928.76 0 0
Steve> 5/25/2000 17:29:11 HostC 3632.60 3300.78 0 0
Steve> 5/25/2000 18:28:37 HostA 2250.16 2136.20 0 0
Steve> 5/25/2000 18:28:52 HostB 905.77 928.76 0 0
Steve> 5/25/2000 18:29:11 HostC 3632.60 3300.78 0 0
Steve> So for instance, I want to select the most current lines (the last
Steve> three).
Steve> Split them into there respective variables $Date $Time $Host $ftpput
Steve> $ftpget $pingloss $pingavg
Steve> Then loop them through a table to display the results on a webpage.
Steve> Thanks for your help,
---------------------------------------------------------------------------------
while(<DATA>)
{
($Date, $Time, $Host, $ftpput, $ftpget, $pingloss, $pingavg) = split(' ', $_);
($mo, $day, $yr) = split('/', $Date);
$nline = sprintf("%04d/%02d/%02d:%s %s %s %s %s %s\n", $yr, $mo, $day, $Time,
$Host, $ftpput, $ftpget, $pingloss, $pingavg);
push(@nlines, $nline);
}
print sort(@nlines), "\n";
__DATA__
5/25/2000 17:28:37 HostA 2250.16 2136.20 0 0
5/25/2000 17:28:52 HostB 905.77 928.76 0 0
5/25/2000 17:29:11 HostC 3632.60 3300.78 0 0
5/25/2000 18:28:37 HostA 2250.16 2136.20 0 0
5/25/2000 18:28:52 HostB 905.77 928.76 0 0
5/25/2000 18:29:11 HostC 3632.60 3300.78 0 0
~sdpm~
The posting address is: san-diego-pm-list at hfb.pm.org
List requests should be sent to: majordomo at hfb.pm.org
If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:
unsubscribe san-diego-pm-list
If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.
More information about the San-Diego-pm
mailing list