in reply to sort strings by date
Again, this is somewhat ugly but it gets the job done in manner that is easy to understand. There is really no need to assign the variables $date and $time, I just thought it would make it easier to understand the process.#!/usr/bin/perl -w use strict; use Time::Local; my $test = "G: CCCCC-01 :ADD : ORDER PROCESSED : *** OK ***:08/30/2003 +:14:24:58"; my $datetemp = substr($test,index($test,"***:")+4,length($test)-index( +$test,"***:")+4); print "DATE & TIME: $datetemp\n"; my $date = substr($datetemp,0,index($datetemp,":")); print "DATE ONLY: $date\n"; my $time = substr($datetemp,index($datetemp,":")+1,length($datetemp)-i +ndex($datetemp,":")); print "TIME ONLY: $time\n"; my @datearray = split(/\//,$date); my @timearray = split(/:/,$time); my $ticks = timelocal($timearray[2],$timearray[1],$timearray[0],$datea +rray[1],$datearray[0]-1,$datearray[2]); print "CLOCK TICKS SINCE THE EPOCH: $ticks\n"; #usage of the timelocal function # my $time = timelocal($sec,$min,$hour,$mday,$month,$year);
|
|---|