Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I've Googled and tried a lot last week, but I'm stuck (on the syntaxis).

I hope you understand my message despite the wording

Actually it seems more like you're stuck on syntax and arrays.

You need to read perlintro and Basic debugging checklist and How do I post a question effectively? and References quick reference

Also, when you have a program, with real, named variables, talking about columns can get confusing , talk about your variables instead ;)

The code you pasted will never have a 12 element array, nor do you want one.

I would go back to

my @sorted = map substr($_, 8), sort map join('', (/(..)-(..)-(....)/)[2,1,0], $_), @dates; # DD-MM-YYYY
Don't get it? To understand, you would write a program like this
#!/usr/bin/perl -- use strict; use warnings; use Data::Dumper; my @dates = qw[ 08-15-2011 08-10-2011 08-05-2011 ]; print "\ndates ", Dumper( \@dates ); #~ my @firstTransform = map join('', (/(..)-(..)-(....)/)[2,1,0], $_) +, @dates; # DD-MM-YYYY my @firstTransform = map join('', ReorderForCmp($_), $_), @dates; # +DD-MM-YYYY print "\nfirstTransform ", Dumper( \@firstTransform ); my @firstSorted = sort @firstTransform ; print "\nfirsSorted ", Dumper( \@firstSorted ); my @finalTransform = map substr($_, 8), @firstSorted ; print "\nfinalTransform ", Dumper( \@finalTransform ); sub ReorderForCmp { my( $one ) = @_; my @date = $one =~ /(..)-(..)-(....)/; #~ return @date[2,1,0]; return $date[2], $date[1], $date[0]; } __END__
which produces this output
dates $VAR1 = [ '08-15-2011', '08-10-2011', '08-05-2011' ]; firstTransform $VAR1 = [ '2011150808-15-2011', '2011100808-10-2011', '2011050808-05-2011' ]; firsSorted $VAR1 = [ '2011050808-05-2011', '2011100808-10-2011', '2011150808-15-2011' ]; finalTransform $VAR1 = [ '08-05-2011', '08-10-2011', '08-15-2011' ];
So yes, it is possible to "map two columns date and time", just adjust sub ReorderForCmp to return iso-8601 style datetime ( YYYYMMDDHHMMSS)

In reply to Re^3: Sorting dates with the Schwartzian Transform by Anonymous Monk
in thread Sorting dates with the Schwartzian Transform by Wobbel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (17)
    As of 2014-08-27 20:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (252 votes), past polls