RE: Why am I getting data from Current Directory?

2005-03-11 Thread 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";
> }



***
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]
 




Re: Why am I getting data from Current Directory?

2005-03-11 Thread John W. Krahn
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?
Once again (sigh):
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;

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);
Or simply:
my $arg_lastchar = substr $ARGV[0], -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 $_ ;
   next if -d "$arg_string/$_";

#
# append upto 30 blanks after the file name #
#
 print $_, " " x (30-length($_)); 
   printf '%-30s', $_;

 print " age of file: ";  # age of file
 
 $Len = index(-M $_, ".");

 print substr(-M $_, 1, $Len-1);
   ^
You do realize that strings start at 0 and not 1?
   print int( -M _ );

 print "\n";
Or combine all the print statements into one:
   printf "%-30s age of file: %d\n", $_, int( -M _ );

}

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Why am I getting data from Current Directory?

2005-03-11 Thread Bret Goodfellow
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.

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, March 11, 2005 3:13 PM
To: Bret Goodfellow; beginners@perl.org
Subject: RE: Why am I getting data from Current Directory?


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";
> }



***
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>




RE: Why am I getting data from Current Directory?

2005-03-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Bret Goodfellow wrote:
> 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.
> 
> -Original Message-
> From: Wagner, David --- Senior Programmer Analyst --- WGO
> [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 11, 2005 3:13 PM
> To: Bret Goodfellow; beginners@perl.org
> Subject: RE: Why am I getting data from Current Directory?
> 
> 
> 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";

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.

Wags ;)
>> }
> 
> 
> 
> ***
> 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>




Re: Why am I getting data from Current Directory?

2005-03-11 Thread John W. Krahn
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:
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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Why am I getting data from Current Directory?

2005-03-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO
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]