The following code gives me a table made from data in lots of small files. It works quite well. However I now need to make it list in date/time order with newest at the top.
opendir THEDIR, "$basepath$ARGV[0]" || die "Unable to open directory: +$!"; @allfiles = grep /^2/,readdir THEDIR; closedir THEDIR; $numfiles = @allfiles; $numfiles = ($numfiles - 2); foreach $file (sort { ($b) <=> ($a) } @allfiles) { if (-T "$basepath$ARGV[0]/$file") { $passflag = 0; open THEFILE, "$basepath$ARGV[0]/$file"; ($ref, $cust, $email, $phone, $mobile, $posted) = <DATAFILE>; close DATAFILE; chomp($ref, $cust, $email, $phone, $mobile, $posted); $file =~ s/\.DAT//; print"<TR><TD>$ref</td><TD>$cust</TD><TD>$email</TD><TD>$phone</TD><TD +>$posted</TD></TR>\n " unless ($passflag); print "</TABLE>\n"; }}}
Actually, I can do this by creating the filenames in a way that lets me sort them in date/time order (don't laugh I am a newbie to perl "year+dayofyear+hour+minute+a few random letters to avoid duplication" this gives me "1022001836abc.dat") this is no longer possible as the data i have to play with now, although holding the same information has a different naming system that I can't change "123456.dat" my question is, How can I create the same table listed in date/time order with the newest at the top regardless of what the filenames are?

In reply to open, chomp, create AND sort ? by Cockneyphil

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.