Re: Modifiaction time of file
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Fri, 28 Apr 2006 09:14:15 -0700
anu p wrote:
Hi,
Hello,
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);
}
}
Any ideas where am I going wrong?
perldoc -f readdir
readdir DIRHANDLE
Returns the next directory entry for a directory opened by
"opendir". If used in list context, returns all the rest of
the entries in the directory. If there are no more entries,
returns an undefined value in scalar context or a null list in
list context.
If you’re planning to filetest the return values out of a
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"readdir", you’d better prepend the directory in question.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Otherwise, because we didn’t "chdir" there, it would have been
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
testing the wrong file.
^^^^^^^^^^^^^^^^^^^^^^^
opendir(DIR, $some_dir) ││ die "can’t opendir $some_dir: $!";
@dots = grep { /^\./ && ‐f "$some_dir/$_" } readdir(DIR);
^^^^^^^^^^^^^^^^^
closedir DIR;
John
--
use Perl;
program
fulfillment
.
- References:
- Modifiaction time of file
- From: Anu P
- Modifiaction time of file
- Prev by Date: Re: looping over an array of hashes
- Next by Date: Re: problem with whitespace not splitting on split.
- Previous by thread: Modifiaction time of file
- Next by thread: Re: Modifiaction time of file
- Index(es):
Relevant Pages
|
|