accessing the string from system(ls -al) / browse dir script

2003-04-06 Thread Motherofperls
I'm trying to put the string from the system(ls -al) into a variable.  It 
simply prints to the page and puts 1 in the variable.

I wan't to use this variable to determine the permissions for the files on a 
linux machine.  Is there an easier way?

Tricia


Re: accessing the string from system(ls -al) / browse dir script

2003-04-06 Thread Li Ngok Lam


 I'm trying to put the string from the system(ls -al) into a variable.  

@list = `ls -al`;

 It simply prints to the page and puts 1 in the variable.

What's that mean '1' anyway ?




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: accessing the string from system(ls -al) / browse dir script

2003-04-06 Thread Paul Johnson
On Sun, Apr 06, 2003 at 07:01:02AM -0400, [EMAIL PROTECTED] wrote:

 I wan't to use this variable to determine the permissions for the files on a 
 linux machine.  Is there an easier way?

opendir
readdir
stat
closedir

perldoc -f each of those for the docs.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: accessing the string from system(ls -al) / browse dir script

2003-04-06 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
 
 I'm trying to put the string from the system(ls -al) into a variable.  It
 simply prints to the page and puts 1 in the variable.

perldoc -f system

 I wan't to use this variable to determine the permissions for the files on a
 linux machine.  Is there an easier way?

The third field returned from the stat (or lstat) function contains all
the permission bits for a file.

perldoc -f stat
perldoc -f lstat
man 2 stat


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: accessing the string from system(ls -al) / browse dir script

2003-04-06 Thread Rob Dixon
[EMAIL PROTECTED] wrote:
 I'm trying to put the string from the system(ls -al) into a variable.  It
 simply prints to the page and puts 1 in the variable.

 I wan't to use this variable to determine the permissions for the files on a
 linux machine.  Is there an easier way?

Hi Tricia.

There's nothing new herem just boiling down the answers that others have
posted:

- system() returns the exit status code of the external program it ran,
  not the output. A value of 1 generally indicates success.

- to get the output of an external program, use backticks: `ls -al` rather
  than system().

- get into the habit of doing things within Perl if you can. This
  increases the chances of your program working on another
  system. opendir/readdir/closedir calls will let you build a directory

- use stat() to get extended information about an existing file ( lstat()
  will do the same for a link )

HTH,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: accessing the string from system(ls -al) / browse dir script

2003-04-06 Thread simran
Stat::lsMode would probably be of interest as well. 

http://search.cpan.org/author/MJD/Stat-lsMode-0.50/lsMode.pm

On Mon, 2003-04-07 at 10:41, R. Joseph Newton wrote:
 [EMAIL PROTECTED] wrote:
 
 
  Hello Mother,
 
  While not knowing exactly what you want to do,
  in general you can use the backtick operators
  to return the output of an external script or
  program; for example, to get a 10 byte string
  of permissions on 'some.file' you could:
 
  $perm = substr (`ls -al some.file`, 0, 10);
 
 I like it!  I'm not much of a 'nix user, and I'd forgotten that you could ls -al for
 a single filename.  This certainly pulls the wanted information in quite elegantly.
 
 Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]