Cockneyphil has asked for the wisdom of the Perl Monks concerning the following question:
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?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"; }}}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: open, chomp, create AND sort ?
by BrowserUk (Patriarch) on Aug 10, 2002 at 11:47 UTC | |
|
Re: open, chomp, create AND sort ?
by mephit (Scribe) on Aug 10, 2002 at 20:01 UTC |