John W. Krahn wrote: > Wagner, David --- Senior Programmer Analyst --- WGO wrote: >> Bret Goodfellow wrote: >>> >>> From: Wagner, David --- Senior Programmer Analyst --- WGO >>> >>> Bret Goodfellow wrote: >>> >>>> 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 $_, "."); >>> >>> Change the $_ to $File::Find::name ( Fully qualified name of file >>> ) Is in the doc. Wags ;) >>> >>>> print substr(-M $_, 1, $Len-1); >>>> print "\n"; > > > >>The File::Find::name didn't seem to make any difference. I still > have >>to be in the directory that I want to search. Hmmm. >> >> It should. I ran a simliar script and had something like: >> printf "%-30s: %5d\n", $File::Find::name, int(-M $File::Find::name); >> >> printed out the integer dates. As john K stated, you are working >> too hard and it can be generated as one line and I would just use >> printf and it's capabilities to line for you. For printing, you >> could use $- which has the filename and for testing then the >> $File::Find::name has the full path and filename. > > The reason it didn't work is because Bret isn't using > File::Find::find() so $File::Find::name is irrelevant. Also $- > doesn't contain the filename: >
Sorry, but just saw the File::find and went right pass it. Also the $- should have been $_ if File::Find had been used, but wasn't. Bret, you can concatenate the $arg_string and $_ to get the file location or if you really want to read deeper into folder(ie, read into other sub folders) then use File::File::find and as stated above to do that. Again I apologize for seeing but not taking the time to really look at the code. Wags ;) > perldoc perlvar > [snip] > $- The number of lines left on the page of the currently > selected output channel. Used with formats. > (Mnemonic: lines_on_page - lines_printed.) > > > > John > -- > use Perl; > program > fulfillment ******************************************************* This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ******************************************************* -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>