Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Need help comparing 4 dates

by dirtdog (Scribe)
on Oct 03, 2010 at 03:37 UTC ( #863133=note: print w/replies, xml ) Need Help??


in reply to Re: Need help comparing 4 dates
in thread Need help comparing 4 dates

Thanks to all for the replies, but I guess my post was a little confusing. My question really is does anyone have a recommendation for the best way to compare 4 dates and then print the order. Comparing 2 dates is easy, but it gets tricky when comparing 4 dates and displaying the order from the earliest to latest as below:

EVENT JIM BOB SAM JACK PTRED 4 3 1 2 RED 3 1 2 4 INT 3 4 2 1 PTRED 2 1 4 3 RED 2 1 3 4 INT 4 3 1 2

I got some ideas from ww and will give it a try. Thanks

Replies are listed 'Best First'.
Re^3: Need help comparing 4 dates
by ig (Vicar) on Oct 03, 2010 at 04:22 UTC

    Given a list of dates, to calculate a corresponding list of ordinals I might do something like the following:

    # Make a list of tuples: (index, date) my @list = map { [ $_, $dates[$_] ] } (0..$#dates); # Sort the list by date @list = sort { Date_Cmp($a->[1], $b->[1]) } @list; # Determine the corresponding ordinal numbers my @ordinals; foreach (0..$#dates) { $ordinals[ $list[$_]->[0] ] = $_ + 1; }

    I don't find this very elegant - there may be much better ways. There may be a module that does this, though I don't know one.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863133]
help
Chatterbox?
[Lady_Aleena]: Hello everyone. I'm having a blonde moment. I can push an array to an array, right? push @to_array, @another_array;
[shmem]: of course
[shmem]: the members of @another_array are conflated to @array
[shmem]: try it out:
[Lady_Aleena]: shmem, thanks. I'm am way out of practice.
[shmem]: perl -lE '@foo = (0..3);@bar = (4..7); push @foo,@bar; say for @foo'
[Lady_Aleena]: shmem, I feel like an idiot for forgetting something so basic.
shmem puts a big cauldron of "silly con charme" on the table in the refectorium

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-04-27 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (503 votes). Check out past polls.