Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Sorting The Date format Values without using any perl modules.

by jesuashok (Curate)
on Dec 26, 2005 at 15:30 UTC ( [id://519154]=note: print w/replies, xml ) Need Help??


in reply to Re: Sorting The Date format Values without using any perl modules.
in thread Sorting The Date format Values without using any perl modules.

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: Sorting The Date format Values without using any perl modules.
by Corion (Patriarch) on Dec 26, 2005 at 15:35 UTC

    Did you read my node? Did you read the sort documentation? Did you look at my example and look how you could adapt it to your needs?

    Please take another look at the sort documentation. Please look at my example (taken from there) and see how you can adapt it to what you need.

    @articles = sort {$a cmp $b} @files;
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: Sorting The Date format Values without using any perl modules.
by wfsp (Abbot) on Dec 26, 2005 at 15:52 UTC
    To add to Corion's comment the arrays in your original post and in your follow up are different.

    It's hard to help if the question keeps moving!

    update: the following is wrong :-(

    Each element in your follow up array is the reverse of those in the origninal. (There's a hint in there!)

    With that observation and another look at the docs I was able to sort the array in the order you're looking for using the method suggested by Corion.

    You didn't say my $sort = (... either.

    update 2:

    Pursuing the reverse theme, perhaps you could consider an intermediate step:

    #!/bin/perl5 use strict; use warnings; use Data::Dumper; my @sort = qw( 05-11-2006 01-01-2005 04-12-2005 22-03-2005 ); my @reversed = map { join '', substr($_, 6), substr($_, 3,2), substr($_, 0,2) } @sort; print Dumper(\@reversed); __DATA__ ---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" _new.pl $VAR1 = [ '20061105', '20050101', '20051204', '20050322' ]; > Terminated with exit code 0.
Re^3: Sorting The Date format Values without using any perl modules.
by blazar (Canon) on Dec 27, 2005 at 14:38 UTC

    Now you changed your requirements in the middle - which incidentally is mostly annoying. If they're as in the OP, then my reply still applies.

    Or else you will have to provide a suitable sort sub, possibly exploiting one of the various sorting techniques often references here and elsewhere. Try checking for example:

    from the Tutorials section. A recent post of mine using a form of Guttman-Rossler is this. In this case you should have fixed length fields and it should be even easier for you to recover the original data with a single substr.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://519154]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found