如何将Perl的系统函数输出存储到变量? [英] How can I store Perl's system function output to a variable?

查看:356
本文介绍了如何将Perl的系统函数输出存储到变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对系统函数有问题.我想将系统功能输出存储到变量中.

I have a problem with the system function. I want to store the system functions output to a variable.

例如,

system("ls");

在这里,我希望当前目录中的所有文件名都存储在一个变量中.我知道我可以通过将输出重定向到文件中并从中读取并将其存储到变量中来做到这一点.但是我想要一种比这更有效的方法.有什么办法.

Here I want all the file names in the current directory to store in a variable. I know that I can do this by redirecting the output into a file and read from that and store that to a variable. But I want a efficient way than that. Is there any way .

推荐答案

否,您不能存储ls输出的值, 由于系统始终将命令作为子进程执行, 因此,请尝试使用反引号"command",它会在当前命令中执行命令 处理本身!

No, you cannot store the values of the ls output , since system always execute the command as a child process , so try with backtick `command` which executes the command in the current process itself!

这篇关于如何将Perl的系统函数输出存储到变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆