Gurus,
I need your help. I have a array that needs to be sorted.
The requirements are :
    weekday (col7)
    time (col8)
    policy (col0)
where
    weekday - format is alphabetic, but order is by day of week
      - Sunday comes first, followed by Monday.....
    time - format is HHH:MM.SS , numeric
    policy - format is alphabethic
I have written a small test program. Code follows
#!/usr/local/bin/perl -w @data = ( "aix-dev,active,aixr03,aixr03,crmd,FULL,12345,Sunday,018:00:00", "w2k-prod,active,w2k-PROD,pub1hi,prod-web-srv1Y,FULL,3,Friday, +021:00:00", "w2k-prod,active,w2k-PROD,pol02pi,prod-web-srv1,CINC,,Monday,0 +09:00:00", "w2k-prod,active,w2k-PROD,pub01pi,prod-web-srv1,CINC,,Monday,0 +23:00:000", "aix-dev-ecmd2,active,aixr03,aixr03,ecmD2,FULL,12345,Monday,00 +1:00:00", "aix-prod-artp,active,aixr04,aixr04,artp-rman,FULL,2345,Sunday +,021:30:00", "w2k-prod,active,w2k-PROD,pol02pi,prod-web-srv1Y,FULL,3,Friday +,023:00:00", "w2k-prod,active,w2k-PROD,pub01pi,prod-web-srv1Y,FULL,3,Friday +,021:00:00" ) ; $count=@data ; print "debug-->data has $count lines \n" ; foreach $line (@data) { chomp $line ; print "$line \n" ; } # Sort on Weekday, time and policy @out1 = sort { @a = (split ',', $a) ; @b = (split ',', $b) ; $a[7] cmp $b[7] || $a[8] cmp $b[8] || $a[0] cmp $b[0] } @data ; $count=@out1 ; print "debug-->out1 has $count lines \n" ; foreach $line (@out1) { chomp $line ; print "$line \n" ; }
1. What do I need to do to make the sort on weekday order by day of week ??
2. How do I split time so I can do numeric compares on HHH, MM,and SS ?
3. How to combine the 3 requirements in one sort statement ?
4. How to make it efficient ( the array could be large ) ?
TIA

In reply to Sort questions by wube

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.