此功能是使用反引号执行系统命令的替代方法。例如,qx(ls -l)将使用-l命令行options执行UNIX ls命令。实际上,您可以使用任何一组定界符,而不仅仅是括号。
以下是此函数的简单语法-
qx EXPR
该函数从执行的系统命令中返回值。
以下是显示其基本用法的示例代码-
#!/usr/bin/perl -w # summarize disk usage for the /tmp directory # and store the output of the command into the # @output array. @output=qx(du -s /tmp); print "@output\n";
执行上述代码后,将产生以下输出-
176 /tmp
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)