I am writing a script to list out a directory's contents, showing the
number of days since modified.  The problem I am having is that the
script doesn't list out the "modified time" unless I change to the
directory being listed.  If I change to the directory I want to list,
then all works okay.  Is there a way to fix this script so that I don't
have to run the script from the current directory?
 
use strict;
use warnings;
use File::find;
use File::stat;
 
my $arg_length;
my $arg_lastchar;
my $arg_string;
my $Len;
 
$arg_length = length($ARGV[0]);
$arg_lastchar = substr($ARGV[0], $arg_length-1, 1);
$arg_string = $ARGV[0];
 
print "Argument: $arg_string\n";
print "length: $arg_length\n";
print "last character: $arg_lastchar\n";
 
print "Contents of $arg_string\n";
opendir DH, $arg_string or die "Couldn't open directory: $arg_string
$!";
 
########################################################################
#
# Read one file at a time into $_
#
########################################################################
#
while ($_ = readdir(DH)) {
 next if $_ eq "." or $_ eq "..";
 next if -d $_ ;
#####################################
# append upto 30 blanks after the file name #
#####################################
 print $_, " " x (30-length($_)); 
 print " age of file: ";  # age of file
 
 $Len = index(-M $_, ".");
 
 print substr(-M $_, 1, $Len-1);
 print "\n";
}

Reply via email to