sorting on time and date

Bobby Kleemann rkleeman at neta.com
Mon Jul 24 13:17:35 CDT 2000


~sdpm~
Your problem is with sorting fixed length versus variable length fields.  
If you could rename all your files so they had the same length in all
fields you'd be set with the standard alphabetical sort (almost, the month
day year will mess you up.  You may want to consider changing that to year
month day if/when you rename the files).

7-24-00-9:40 -> 07-24-00-09:40

The other option is to split the fileds and sort in a sane way:

sort {
	my @a = split /\W/, $a;
	my @b = split /\W/, $b;
	$a[2] <=> $b[2]
		or
	$a[0] <=> $b[0]
		or
	...
}

If you are doing this much work you'll probably want to throw it into a
Schwarzian transform to speed up the sorting if there are a lot of files.  
That involves changing your simple sort {} @data to a map {} sort {} map
{} @data, which can get ugly until you are used to it.
 _ _ _
 Bobby Kleemann <rkleeman at neta.com>
     http://www.neta.com/~rkleeman/

On Mon, 24 Jul 2000, Steve Meier wrote:

> ~sdpm~
> 
> Hello all,
> 
> I am trying to sort some files. When I collect my data, I name the files
> mm/dd/yy-hh/mm. (e.g. 7-24-00-9:40). I am using the standard sort
> function to try to achieve my results:
> 
> @sorted = sort {$a <=> $b} @unsorted;
> 
> However, it is not working as expected? After 10am, the files are sorted
> out of order. Does anyone know the right way to sort these files?
> 
> Thanks,
> 
> Steve
> 
> ~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.
> 

~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