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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.