Apache version 2.2.11 (Unix) Architecture x86_64 Operating system Linux Kernel version 2.6.18-164.el5
Ok, here is what I have working. However, I may not be using File::Util
for anything else in the rest of the script.
My directory names are 8 digits starting at 10000000 .
I was comparing the highest found number with stat last created
as a double check but, overkill I believe.
Another issue is that I did not know how to slap a regex in the list_dir
command so only 8 digits eg m!^([0-9]{8})\z!x)
could reside in that string. Reading the man, the example reads ....'--pattern=\.txt$')
but, my futile attempt: '--pattern=m!^([0-9]{8})\z!x)')
well, was just that.
So, would there be a "better" way to grab the latest folder/directory?
use File::Util;
my($f) = File::Util->new();
my(@dirs) = $f->list_dir('/home/accountname/public_html/topdir','--no-fsdots');
my @last = (sort { $b <=> $a } @dirs);
my $new = ($last[0]+1);
print "Content-type: text/html\n\n";
print "I will now create dir $new\n";
And.. How would I ignore anything not matching my regex?
I was thinking an answer may reside in ls -d
as well but, as a beginner here, I am new to system calls from a script (and if in fact that's what that would be? ;-) ).
So, more specifically:
Best way to open a directory, return the name of the latest 8 digit directory in that directory ignoring all else. Increase the 8 digit dir name by 1 and create the new directory.
Whichever is most efficient: stat
or actual 8 digit file name. (directory names are going to be 8 digits either way.) Better to use File::Util
or just built in Perl calls?
Thanks to everyone in advance. I have learned so much here.