Re: Date function



K.J. 44 wrote:
Hi,

is there a date function in Perl or do I have to try to find a module?

What i need is to be able to come up with the current date, then
subtract one day, and add that to the file name in the form of:

YYYY-MM-DD-RestOfFileName.txt

The script I have written parses these files and I want to run it every
night after midnight on the previous days file which has the naming
convention above.

I am running ActiveState Perl in a Windows environment.


You can use the Date::Format module.

use strict
use Date::Format;
my $yesterday = time() - ( 24 * 60 * 60 );
my $prefix= time2str("%Y-%m-%d", $yesterday);
# YYYY-MM-DD-RestOfFileName.txt
print $prefix."-RestOfFileName.txt"
.



Relevant Pages

  • Re: When to "use strict" when teaching?
    ... >>being influenced by the history of Perl ... history bias you" essentially the same as saying you are not ... An understanding of how symbolic references work is neither necessary ... I say don't expose people to the idea of omitting "use strict" until ...
    (comp.lang.perl.misc)
  • RE: I need help here
    ... Here's the Big Secret about Perl variables that most people learn ... use strict; ... : $outputfile = shift; ... You will often see a usage message in a script which deals ...
    (perl.beginners)
  • RE: simple references question
    ... Perl will not. ... Subject: simple references question ... If you want to alter the contents of the original array, ... Always use strict and warnings. ...
    (perl.beginners)
  • Re: Annoying HASH(0x...) in Output
    ... Perl will tell you if you forget a 'my'. ... A reference to an empty hash? ... same @friends that we saw earlier, the package variable also known as ... If that doesn't sell you on 'use strict', ...
    (perl.beginners)
  • Re: Class::Struct: Cant access struct field elements
    ... this compiles on my system if I omit use strict. ... Programming Perl, because it doesn't compile. ... I'm unable to dereference any array elements in the struct. ...
    (perl.beginners)