http://www.perlmonks.org?node_id=264384

campbell has asked for the wisdom of the Perl Monks concerning the following question:

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