Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing results of "ls" command into an array

Status
Not open for further replies.

bitz2000

Programmer
Feb 18, 2003
6
0
0
CA
From a perl program, I'm trying to issue an "ls" command and capturing the results into an array instead of placing it into a file. I need to be able to look at each line of the output and pick out certain pieces of information.

With the command below, I have been able to capture the output but I can't dissect it into individual lines. Is there a way to do this - and if so - how can it be done?

I'm not a newbie to Perl however I am definitely far from being an expert.

Command I'm using:
$output = system("ls *.txt -lt");

Thanks in advance for any help you send me.

 
bitz2000 - Try @output = system("ls *.txt -lt"); . Then you can do something with each line..

- V.
 
Thanks for the input - tried that. Still didn't work. Sorry I didn't say that in my original note.
 
I just tested it and worked fine for me. What is the error you are getting?

- V.
 
I never thought that you could get output at all using the [tt]system[/tt] function.

You could do:
[tt]my @output = `ls *.txt -lt`;[/tt]
 
Thank you SO MUCH to the both of you (rosenk and kudithipudi)! The "my @output = `ls *.txt -lt`;" worked like a charm. You don't know how long I've been banging my head on this one. I was able to output the results to a file using the system command but not to an array (which is what I really wanted in the first place).

Life is now much easier!

Take care.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top