SPUG: Win32 Sorting directory by date
Mark Yocom
myocom at microsoft.com
Wed Oct 3 12:10:45 CDT 2001
The problem with your script doesn't lie in NT, it lies in the fact that
you are referring to two different arrays. You assign to @FILES and
then reference @AllFiles2 in your print.
Changing your code such that there's only one array returns accurate
results on my Win2K box.
opendir(DIR, ".");
my @files = sort { -M $a <=> -M $b } readdir(DIR);
print "The files you requested:\n". join("\n", @files) ."\n";
close(DIR);
I might also recommend using strict, which will catch errors like this
(and also force you to declare your variables ahead of time).
> -----Original Message-----
> From: Bryan Dees [mailto:Bryan.Dees at airborne.com]
> Sent: Wednesday, October 03, 2001 9:49 AM
> To: Spug-List (E-mail)
> Subject: RE: RE: SPUG: Win32 Sorting directory by date
>
>
> Thanks for the followup's everyone. Your solutions work
> perfectly under
> Unix.
> However, the provided solution doesn't sort files under Microsoft's
> 'challenged' NT OS:
>
> opendir(DIR, ".");
> @FILES = sort { -M $a <=> -M $b } readdir(DIR);
> print "The files you requested:\n". join("\n",
> @AllFiles2) ."\n";
> close(DIR);
>
>
> Thank you for your continued support.
>
> Bryan Dees
> Distributed Systems Analyst
> Airborne Express
> bryan.dees at airborne.com
>
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your
> Email-address
> For daily traffic, use spug-list for LIST ; for weekly,
> spug-list-digest
> Seattle Perl Users Group (SPUG) Home Page:
http://zipcon.net/spug/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
More information about the spug-list
mailing list