in reply to Re^3: some problem with date
in thread some problem with date

Hi sorry to bother you much. is it possible with the current code i have put in the top we can do something,the reason i am asking this is we have lots of procedure to install this modules in that box. Again i am sorry if i bother you much on this

Replies are listed 'Best First'.
Re^5: some problem with date
by ikegami (Patriarch) on Apr 16, 2007 at 13:53 UTC

    By the way, do you know you don't need to be root to install a module locally?

    I do know one way, but it's rather ugly.

    use strict; use warnings; use File::Spec qw( catfile ); use Time::Local qw( timegm ); sub localdate { my ($time) = @_; my ($y, $m, $d) = (localtime($time))[5, 4, 3]; $y += 1900; $m += 1; return ($y, $m, $d); } sub previous_day { my ($y, $m, $d) = @_; # Use GMT since all days are 24*60*60 seconds long in GMT. my $prev = timegm(0, 0, 0, $d, $m-1, $y) - 24*60*60; my ($p_y, $p_m, $p_d) = (gmtime($prev))[5, 4, 3]; $p_y += 1900; $p_m += 1; return ($p_y, $p_m, $p_d); } sub today { return localdate(time()); } sub yesterday { return previous_day(today()); } { my ($yd_y, $yd_m, $yd_d) = yesterday(); my $dir = ...; opendir(my $dh, $dir) or die("Unable to open log dir \"$dir\": $!\n"); while (my $file_name = readdir($dh)) { my $file_full = catfile($dir, $file_name); next if ! -f $file_full; my $mtime = (stat($file_full))[9]; my ($f_y, $f_m, $f_d) = localdate($mtime); if ( $f_y == $yd_y && $f_m == $yd_m && $f_d == $yd_d ) { ...copy the file... } } }

    Update: Fixed order or params for timegm.

      hi Thank you but i could find an error that DAY 2007 is out of range 1...30 line 19.
        I hope you figured out that's because I had the parameters to timegm in the wrong order. Fixed.