Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by jesuashok (Curate)
on Dec 26, 2005 at 15:30 UTC ( #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.

Hi,

Please look into the above code. I tried using sort also. But then I am facing the Issue.

#!/usr/bin/perl + + @sort = ( '05-11-2006', '01-01-2005' , '04-12-2005' , '22-03-2005'); + + foreach (sort @sort) { print ":$_:\n"; }
OUTPUT: :01-01-2005: :04-12-2005: :05-11-2006: :22-03-2005:
Please Note the output carefully. I want to that to be sorted. Please provide me your Idea.

"Keep pouring your ideas"


Comment on Re^2: Sorting The Date format Values without using any perl modules.
Select or Download Code
Re^3: Sorting The Date format Values without using any perl modules.
by Corion (Pope) 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;
      Hi

      I tried your Suggestion and that too is giving wrong result. anyway thanks a lot for your answers.

      "Keep pouring your ideas"
        Put some code to show how you tried the suggestion. Vaguely saying "that too is giving wrong result" undermines your credibility and makes other viewers think that the suggestion was wrong (which is not the case).
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
Node Status?
node history
Node Type: note [id://519154]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-07-24 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls