From: "Roger Grosswiler" <[EMAIL PROTECTED]>
Subject: Date manipulation
Date: Tue, 10 Feb 2004 11:21:15 +0100 (CET)

> hi list,
> 
> i'd like to try a first perl-script that should:
> 
> -define todays date
> -define todays date minus one week
> -find in a special directory files, that contain ddmmyy
> -remove them
> 
> ..since i am an absolute beginner in programming...i think, if i can read
> out this directory, i can find the files with regexp.
> 
> But: how can i find out the Systems-Date with Perl? Which format has it?
> Is there a perlman-page? (I was looking, but didn't find...)
> 

Read the perlfunc man page. It will contain detailed information about
time related issues:

       Time-related functions
           "gmtime", "localtime", "time", "times"


The localtime and time are your functions.

Some code:

   $nowstring = localtime ; ## current sys-time
   ($wday,$mon,$day,$timestr,$year) = split(/ /,$nowstring) ;
   ($hh,$mm,$ss) = split(/:/,$timestr) ;

Try to run this, print the vars, and you will see how it works.

Use the time function to time to get the seconds from Jan 1st
1970. You will be able to do any calculation you want.

>From man perlfunc:

      time    Returns the number of non-leap seconds since whatever time the
               system considers to be the epoch (thats 00:00:00, January 1,
               1904 for Mac OS, and 00:00:00 UTC, January 1, 1970 for most
               other systems).  Suitable for feeding to "gmtime" and "localtime".

               For measuring time in better granularity than one second, you
               may use either the Time::HiRes module from CPAN, or if you have
               gettimeofday(2), you may be able to use the "syscall" interface
               of Perl, see perlfaq8 for details.

Good luck,

Gabaux
Linux is like a wigwam: no gates, no windows, and an apache
inside!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to