Wiser Monks Than I(TM) can provide specific answers to your question.
But a Super Search for unique filename timestamp date turned up some hopefully helpful threads:
I vaguely recall a question just like yours sometime in the past few months, but haven't found it.
Good luck, and let us know how you end up handling this.
cheers,
ybiC | [reply] |
If I understand you correctly, you want to place a timestamp at the end of the filename. I'd advise against this because it prevents some machines from associating the file to an extension. Instead build the filename and place the timestamp in a location where you can easily get at it.
e.g.
# read info
# and then we are ready to build our filename
# unless you are writing binary data, the following should
# do the trick.
$time = time;
$filename="myfile_".$time.".txt";
# (and then just print using $filename)
time will give a machine-readable time in seconds from the epoch. It should be a valid way of doing things until around 2030. Hopefully, by then we won't have computers :)
If the time needs to be readable by a human, you can do something like:
$time = scalar localtime;
$time =~ tr/ /_/; #get rid of the spaces;
$filename = "myfile-".$time.".txt";
| [reply] [d/l] [select] |
This won't work, because it returns the current date. First, there's a typo in my post. The example should read:
/export/home/mars-stats/device/config/2000/0825/blah/blah/blah.txt
Your code would return:
"blah-Sun_Aug_27_03:18:29_2000.txt"
Which is a problem, if I want to run the program on a month old file, and create a file with THAT date on it.
So, my new brilliant (?) idea is the following:
Since each day, a new directory is created which contains the files I need to process, read the path to the file that I want to process:
#get current working directory; let's say it returns:
$path = "/export/home/mars-stats/device/config/2000/0825/blah/blah/blah.txt"
Then create the rule:
if while reading $path, you encounter:
begins with "/", followed by 1 or more "/", then one or more word characters, then a "1" or
a "2" followed by more than one digit, followed by one or more word characters
until the end of the line, grab the string between the first word
character preceding a digit and the next word character,and replace the "/" with "."
this should return "2000.0825" which I could use to append to my new file.
This rule, if I can figure out the syntax, would cover any input file created in between the years 1900 - 2999. Not bad mileage!
Am I missing something here? Be gentle; this is the first program I've ever written in ANY language!
| [reply] |