Hi
So, you are running through the files on the server and you want to fetch only those whose names end with _Jul282009_2358.zip (for the current date).
One way to get the date in that format is using POSIX::strftime. Here is a quick test:
use strict; use warnings; use POSIX qw(strftime); print strftime("arident16_%b%e%Y_2358.zip\n", gmtime); output: arident16_Jul292009_2358.zip
One potential problem with strftime is that the output depends on your locale settings. In other words, the abbreviation Jul may come out differently (in a different language, for example). If so, you could continue constructing the timestamp manually, as you attempted at the top of your code. I will continue with strftime for now, because it makes the code smaller.
So to insert into your code:
### at the top of the file: use POSIX qw(strftime); ### ... ### just before your foreach loop: my $files_to_match = strftime("%b%e%Y_2358.zip", gmtime); foreach $file (@list) { # N.B. I am assuming $file contains the filename here. # skip files that don't end with $files_to_match # N.B. could use regex here, not sure what's faster. next unless substr($file, 0 - length($files_to_match)) eq $files_to_match; ### Then what you did already. I didn't check that. } ### quit, etc...
I have tested the above in a very basic way...
I didn't check the rest of your code because it seems like you are just asking how to skip files that don't match. I did notice that you are using a mixture of print and printf. In Perl, you generally use print most of the time and only need printf or sprintf when using the formatting strings (%0.2d, etc.). You should think about using warnings and strict (as in my strftime example script, above).
Hope this helps.
In reply to Re: date in required format
by FalseVinylShrub
in thread date in required format
by namishtiwari
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |