list sorting problem, please help 
Author Message
 list sorting problem, please help

I have a list of dates/times with a number that looks something like:

5/17/2003  10:08:00AM 10
5/17/2003  10:28:00AM 10
5/17/2003  10:30:00AM  5
5/17/2003  10:32:00AM 10
5/17/2003  10:55:00AM  6
5/17/2003  11:28:00AM  3

I can convert the date and time for each line into epoch time but I'm
having trouble figuring out how to sort the information. I'm trying to
get it so any number entry within 10 minutes of the next number entry
will be added to the next and put on same line. I would like to
specifics each entry that has been added together displayed on the
same line afterwards to look like

5/17/2003  10:08:00AM 10
5/17/2003  10:32:00AM 25, 10 10:28, 5 10:30, 10 10:32
5/17/2003  10:55:00AM  6
5/17/2003  11:28:00AM  3

I can convert the dates and times and trim the times so only the time
shows. But for the comparing of the previous entries in the list I've
tried several things including holding a previous entry in a scalar
then comparing the next entry to the previous and working from there.
The code gets messy and I end up back where I started. And it seems
like a bad approach by design.

Could someone give me some ideas on how to even start coding this?

thanks,
Dave



Sun, 06 Nov 2005 04:52:58 GMT  
 list sorting problem, please help


Quote:
> I have a list of dates/times with a number that looks something like:

> 5/17/2003  10:08:00AM 10
> 5/17/2003  10:28:00AM 10
> 5/17/2003  10:30:00AM  5
> 5/17/2003  10:32:00AM 10
> 5/17/2003  10:55:00AM  6
> 5/17/2003  11:28:00AM  3

> I can convert the date and time for each line into epoch time but I'm
> having trouble figuring out how to sort the information. I'm trying to
> get it so any number entry within 10 minutes of the next number entry
> will be added to the next and put on same line. I would like to
> specifics each entry that has been added together displayed on the
> same line afterwards to look like

> 5/17/2003  10:08:00AM 10
> 5/17/2003  10:32:00AM 25, 10 10:28, 5 10:30, 10 10:32
> 5/17/2003  10:55:00AM  6
> 5/17/2003  11:28:00AM  3

> I can convert the dates and times and trim the times so only the time
> shows. But for the comparing of the previous entries in the list I've
> tried several things including holding a previous entry in a scalar
> then comparing the next entry to the previous and working from there.
> The code gets messy and I end up back where I started. And it seems
> like a bad approach by design.

Not sure that this would be a lot (or at all, for that matter) cleaner than
your approach, and I'm also expecting someone to come along and show us how
to do this all in one line, but this is how I would accomplish it (with a
simplified date structure):

#!/usr/bin/perl -w
use strict;


10:32 /;



my $i = 0;

    if ($vals[$i] and
        abs($val->{epoch} - &to_epoch($vals[$i]->[0])) >= (60 * 10)){
            $i++;
    }

Quote:
}



Quote:
}

sub to_epoch {
    my ($hours, $mins) = split ':', $_[0];
    ($hours * 60 * 60 ) + ($mins * 60);

Quote:
}

I'm looking forward to hearing some other (cleaner) approaches on this one
though...

Gabriel



Mon, 07 Nov 2005 00:49:37 GMT  
 list sorting problem, please help
Quote:
> my $i = 0;

>     if ($vals[$i] and
>         abs($val->{epoch} - &to_epoch($vals[$i]->[0])) >= (60 * 10)){
>             $i++;
>     }

> }



> }


array of hashes?
And no need to use abs - they have been sorted already after all.

my $isec = 60*10;
my $phash;

        if( $vals[-1] and ($val->{epoch} - $vals[-1]->{epoch} <= $isec )) {

        } else {
                $phash = [$val->{val}];

        }

Quote:
}



Quote:
}
> I'm looking forward to hearing some other (cleaner) approaches on this one
> though...

Not much cleaner <BG>.

Regards,
Bulat Baltin.



Tue, 08 Nov 2005 18:09:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. again a sort problem (help me please: newbie)

2. help sorting list of lists/nested array

3. Simple Question lists of lists - please help!!

4. Please help complete holiday/country list (was: Need list of all legal holidays in all countries)

5. Please help complete holiday/country list (was: Need list of all legal holidays in all countries)

6. re-sorting a sorted list (and sorting by date)

7. Help with sorting Hashes (Lists of Hashes)

8. help with sorting html list

9. Bunny's sort the list, help.

10. PERLFUNC: sort - sort a list of values

11. PERLFUNC: sort - sort a list of values

12. insert to sorted list via sort?

 

 
Powered by phpBB® Forum Software