Hello,
I'm trying to do a Perl script on Windows (wish it was Unix) that goes to a directory, figures out which files are most recent, within the last week, then copies them to another dir. I'm stuck at the sorting of the files in a directory. This part of the code returns a list but it's not sorted by date: - opendir(INPUTINFO, ".") or die "Doesn't work: $!";
-
my @xmlfiles = grep /\.xml$/, readdir INPUTINFO;
-
my@sorted =
-
map {join'/',(split/-/)[1,2,0]}
-
sort
-
map {join'-',(split'/')[2,0,1]}
-
qw(12/31/2000 12/26/2000 01/01/2001), @xmlfiles;
-
print "$_\n" for @xmlfiles;
-
print "\n";
I'm guessing it's the sort. Would file::stat work better?
Thanks,
TEVO
3 3073
To sort the files based on modified time/date, you can make use of stat() function : -
print "$_\n" foreach(sort {(stat($a))[9]<=>(stat($b))[9]} @xmlfiles);
-
To sort the files based on modified time/date, you can make use of stat() function : -
print "$_\n" foreach(sort {(stat($a))[9]<=>(stat($b))[9]} @xmlfiles);
-
Yes, but that is not very efficient since it will have to stat() files more then one time. Better to build an array or hash of sort keys first, then sort the keys.
Yes, but that is not very efficient since it will have to stat() files more then one time. Better to build an array or hash of sort keys first, then sort the keys.
Agreed. Thanks for the update Kevin :) -
$stathash{$_} = (stat($_))[9] foreach(@xmlfiles);
-
print "$_\n" foreach(sort {$stathash{$a}<=>$stathash{$b}} keys %stathash);
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian |
last post by:
I have an array like this:
$events = array(
array(
'2003-07-01',
'Event Title 1',
'1' //ID Number (not unique)
),
array(
'2003-07-02',
|
by: cat_dog_ass |
last post by:
I am used to programming in DOS mode via Borland C++. I would now like
to create programs for the Windows envirinment. Is it absoultely
necessary to use Visual C++ to do this? Are there other tools...
|
by: VK |
last post by:
Hello,
In my object I have getDirectory() method which returns 2-dimentional
array
(or an imitation of 2-dimentional array using two JavaScript objects
with auto-handled length property - please...
|
by: Stefan |
last post by:
What sorting-algorithm is Array.Sort based upon? Is it an effective way of
sorting an array?
Regards,
Stefan
|
by: able |
last post by:
Dear friends
I have loaded a huge amount of data in an two domensional array. I need to
do a lot searching in the array and sorting the array. My question is if an
array is the most apropriate...
|
by: schmud |
last post by:
i'm having trouble correctly sorting dates in my dataview. It will sort the column but it just sorts according to the month number. I need to display the data on my companies site with the most...
|
by: pob |
last post by:
I currently have a procedure that loops thru a recordset to determine
what files need to be loaded to my database. The naming convention of
the files has always been accounts.txt, namelist.txt,...
|
by: darrel |
last post by:
We have a home grown web site. We store page information, including a
time-stamp as to when it was last updated in a database table.
We also store the site architecture (navigation) in an XML...
|
by: lukasso |
last post by:
Hi, this is my code that should produce something like a timetable for a few days with each day divided into 30 minute pieces. It makes query from MySQL and then creates a 2d $array which then is to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |