Gossamer Forum
Home : General : Perl Programming :

dir sort

Quote Reply
dir sort
Hi,

I want to know how to return the most recent file in a dir.
When a new clients sign up I put them in a new dir and then display the new users name using the print command.

Here is what I have at present:

Code:
#!/usr/bin/perl

#-#############################################
# Sub: Welcome Message
# This will give out a welcome message to
# the newest member;

$basepath = '/home/----/---------/'; erased for obvious reasons.....
$newmember = 'nm';
print "Content-type: text/html\n\n";
opendir THEDIR, "$basepath$newmember" || die "Unable to open directory: $!";
@allfiles = readdir THEDIR;
closedir THEDIR;
foreach $file (sort { int($a) <=> int($b) } @allfiles) {
if (-T "$basepath$newmember/$file") {
open THEFILE, "$basepath$newmember/$file";
($alias) = <THEFILE>;
close THEFILE;
chomp($alias);
}
}
print "<img src=\"http://www.auctionenid.com/images/smiley2.gif\">&nbsp;<font[/url] face=\"verdana,Arial\" color=\"black\" size=\"1\">AuctionEnid welcomes it's newest member<br><b>$alias</b></font>";
#------------------------------------------------------#


What it is doing is not returning the latest file in the dir (nm)

I had a file named Loop_y (entered last week) and one called Ebe01 (today) and it's returning the L_oopy file.

Sorry the explanation is not great I'm new to PERL



many thanks

CEO

Last edited by:

ceo: Oct 20, 2003, 7:32 AM
Quote Reply
Re: [ceo] dir sort In reply to
...this seems to be sorting the directory listing (files) in alphabetical order.

How can I get it to sort the dir listing by date...latest one first?



thanks

CEO