I'm a PHP guy, but choose to do my file scripts in perl and have come upon this problem:
I have n files with a date in their name: test2010-08-23.txt for example.
I want grab (using glob or whatever else) the last x number of files.
Example assuming today is Aug 23rd, the last 4 days would grab the files for the 22nd, 21st, 20th, and 19th of August.
test2010-08-19.txt
test2010-08-20.txt
test2010-08-21.txt
test2010-08-22.txt
Is there a better way to do this other than back tracing with a -1 forloop?
Expand|Select|Wrap|Line Numbers
- // my current plan in *pseudo* code, the forloop
- days = 7
- @testfiles = array();
- for(i = days; i > 0; i--)
- {
- aFile = 'test'.formatdate("yyyymmdd",today - i).'.txt';
- if(file_exists(aFile)
- push(@testfiles,aFile);
- }
Thanks All,
Dan