save output to array

A

a

Hi,
For example,
If I want to save the output of system("ls") to an array, what should I do?
Thanks a lot
 
J

Jürgen Exner

a said:
If I want to save the output of system("ls") to an array, what should
I do?

I would follow the advise that is given in the man page and the FAQ about of
system().
Like e.g. the fourth sentence in the third paragraph of "perldoc -f system".
Or the answer to "perldoc -q system": "Why can't I get the output of a
command with system()?"
Or any of the gazillion previous threads about this topic.

Having said that, why do you want to capture the output of 'ls' in the first
place?
There are several Perl builtin functions that provide the same
functionality, no need to shell out an external process.

jue
 
A

a

Thanks for you reply.
Actually, I need to look for the file path of the given file name.
Do perl have support for this?
Thanks a lot.
 
J

Josef Moellers

Peri said:
One can download the core module File::Find from the CPAN

Why do you write that? Who are you talking to? What problem does your
solution solve?

Please quote when replying.
 
P

Paul Lalli

Peri said:
One can download the core module File::Find from the CPAN

Well, yes, one *could* download a core module from CPAN, I suppose, but
why would one *want* to? Core modules.... are core modules. They are
already included in your distribution of Perl.

Can you explain what problem you are attempting to solve?

Paul Lalli
 
P

Peri

Paul & Josef
Apologies if my pointer was dangling.

Just wanted to help "a" with the requirement of file path lookup given
a file name & file::find does help him towards achieving what he wants
with out the need for him to execute the system utilities.

Please correct me if I am wrong.
 
P

Paul Lalli

Peri said:
Paul & Josef
Apologies if my pointer was dangling.

Just wanted to help "a" with the requirement of file path lookup given
a file name & file::find does help him towards achieving what he wants
with out the need for him to execute the system utilities.

Please correct me if I am wrong.

You are not wrong that File::Find could help the stated problem.

You are wrong in that you are not quoting any context when you are
posting your replies (see how I've quoted what you wrote above? You're
not doing that) so that no one who A) is not reading this newsgroup in
a threaded manner, or B) is using a newserver which has not yet
received the original message, has any idea what you're talking about.

You are also wrong in that File::Find would need to be downloaded via
CPAN. It is already included in the standard Perl distribution. If
you have Perl, you have File::Find. Just use it.

Paul Lalli
 
J

John Bokma

Having said that, why do you want to capture the output of 'ls' in the
first place?
There are several Perl builtin functions that provide the same
functionality, no need to shell out an external process.

Sometimes an external process is easier, so don't be afraid of it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top