Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need a script that will print the time and date to a file. I can get the time and date output just fine, but I have no idea on how to output it to a file.

20030719 Edit by Corion: Moved to SoPW

Replies are listed 'Best First'.
Re: Time and Date Output
by TVSET (Chaplain) on Jul 20, 2003 at 00:50 UTC
    Here is one from the top of the head:

    #!/usr/bin/perl -w use strict; use POSIX qw(strftime); my $date = strftime "%Y-%m-%d %H:%M:%S", localtime(time); open(OUT, ">myfile.date") or die "Oopsy: $!"; print OUT $date,"\n"; close(OUT);

    Leonid Mamtchenkov aka TVSET

      TVSET,
      hmmm - I'm too lazy for that
      perl -e 'print scalar localtime' > myfile.date
      Just change the single quotes to double quotes if it is on Win32.

      Cheers - L~R

        Bah, you call that lazy? :)

        $ date > myfile.date

        Even the perl version's shorter.

        $ perl -e 'print `date`' > myfile.date