RE: Modifiaction time of file





-----Original Message-----
From: anu p [mailto:anu_subj_info@xxxxxxxxx]
Sent: Friday, April 28, 2006 11:51 AM
To: beginners@xxxxxxxx
Subject: Modifiaction time of file

Hi,

I have a requirement where I need to look at the age
of file, if it's older than 2 days, I should remove
it.
I am trying to use the '-M ' filehandle in my script,
it does not work.

I get the following error
Use of uninitialized value in numeric gt (>) at
./temp_age.pl line 12.


#!/usr/bin/perl

use strict;
use warnings;

my $fail_dir =
"/home/anupamaperi/failed_tests/regress_26";
my ($file, $age);

opendir (DIR, $fail_dir) || die "cannot open, no
$fail_dir dir $!";
while ($file = readdir (DIR)) {
if (-M $file > 2) {
print("$file\n");
unlink($file);
}
}

readdir() returns directory entries in a list context if any entries
exist and undef if there is nothing. You should read the entries in an
array and iterate over that:

my @files2check = readdir( DIR );
foreach my $file ( @files2check ) {
if ( -M $file > 2 ) {
...
}
}

ry

Any ideas where am I going wrong?

Thanks,
Anu.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>


.



Relevant Pages

  • Re: smartd failed
    ... >> Do You Yahoo!? ... Mail has the best spam protection around ... > The default behaviour of smartd is to auto-detect the drives, ... > to find out which entries in /dev are your hard drives, ...
    (Fedora)
  • how to exclude these entries in syslog.conf
    ... I have the following entries in my syslog.conf, and local2,3,4.warn log will go into ... May I know how to exclude the local.2,3,4.warn in /var/log/messages? ... Do You Yahoo!? ... Mail has the best spam protection around ...
    (Fedora)
  • java in Linux question
    ... whether i should create JAVA_HOME variable like windows do ?? ... Do You Yahoo!? ... Mail has the best spam protection around ...
    (Fedora)
  • FreeBMD Postems
    ... Sharon ... Do You Yahoo!? ... Mail has the best spam protection around ...
    (soc.genealogy.britain)
  • Re: nfs client readdir caching issue?
    ... duplicate directory entries. ... a first cookie value of 13. ... In the other capture, the responses ... Subsequently, the readdir cache needs ...
    (Linux-Kernel)