RE: Reg. Directory listing program

-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
Sent: Wednesday, June 04, 2008 11:08
To: Gunwant Singh; beginners@xxxxxxxx
Subject: RE: Reg. Directory listing program

-----Original Message-----
From: Gunwant Singh [mailto:gunwant.s@xxxxxxxxx]
Sent: Wednesday, June 04, 2008 10:02
To: beginners@xxxxxxxx
Subject: Reg. Directory listing program


I am new to this mailing list and I am very new to PERL. So,
please bear
with me for my questions.
I wrote a code that lists files in a directory with the
permissions. I am
coding for MS-Windows.
Here is my code:

*1 use strict;
2 use warnings;
3 use File::stat();
5 opendir (DH, "subcode") or die "$!";
6 foreach my $file(readdir DH)
7 {
8 my $perm=stat($file)->mode;

you need something like:
my $filestat = stat($file);
my $perm=$filestat->mode;
I was looking at Programming Perl and if you want to make sense
of the mode, then should 'and' with 07777 and print out using %04o (
octal output ), so something like:
my $perm=$filestat->mode & 07777;

but this will not work correctly unless you are already positioned on
the right directory location. So either you can do a chdir to
the folder
you are doing or a concatenate of "subcode" . $file to get the file
status correctly.

Wags ;)

9 print "$file\t$perm\n";

Then change print to
printf "$file %04o\n", $perm;

Wags ;)

10 }
11 closedir (DH);

*I am getting the listing of file just fine if I dont add
line 8. But as
soon as I try to display the permissions, I get this:

*Can't call method "mode" without a package or object reference at
C:\Documents a
nd Settings\Myself\Desktop\code\ line 8.

*What am I doing wrong!


Gunwant Singh

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: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx