Hi. I am new to Perl and I am trying to sort a list of documents according to the date they were issued, and display the sorted list as a table. (At the moment they are sorted according to title.)

At the moment, what I am doing is this:

I have the documents listed in a subdirectory, and I create an array of the documents using:

@array=readpipe 'ls 'directory'/'subdirectory'.*html' ;

The list is then sorted using:

sort @array;

The issue date of each document has already been stored in the document header as 'description'. The titles and issue dates and are therefore extracted from the documents, and turned into a table, as follows:

@headings=('Title','Issue Date'); @rows=th(\@headings); foreach $n (@array) { open (HTMLFILE,$n); $issue_date=""; while (<HTMLFILE>) { if (m/<TITLE>(.+)<\/TITLE>/i){$title=$1}; if (m/<o:Description>(.+)/o:Description>/i) {$issue_date=$1}; } close HTMLFILE; push(@rows, td([$title,$issue_date]) } print table({width=>"100%",border=>"1",bordercolor=>"#d9dae6",cellspacing=>" +1",cellpadding=>"1"},Tr({bgcolor=>"#97a5f0"},\@rows));

I would like to modify this whole program so that the documents are sorted according to issue date, rather than title.

There's probably some really simple way of doing this. Can anybody tell me what it is?

Thanks,

Campbell Reid


In reply to Sorting according to date by campbell

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.