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