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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting according to date
by hipe (Sexton) on Jun 09, 2003 at 19:18 UTC | |
by sauoq (Abbot) on Jun 09, 2003 at 21:19 UTC | |
by hipe (Sexton) on Jun 10, 2003 at 11:11 UTC | |
by campbell (Beadle) on Jun 12, 2003 at 15:33 UTC | |
Re: Sorting according to date
by sauoq (Abbot) on Jun 09, 2003 at 17:28 UTC | |
Re: Sorting according to date
by OM_Zen (Scribe) on Jun 09, 2003 at 17:13 UTC | |
by sauoq (Abbot) on Jun 09, 2003 at 17:27 UTC | |
by OM_Zen (Scribe) on Jun 09, 2003 at 17:40 UTC |
Back to
Seekers of Perl Wisdom