温馨提示×

Perl中怎么调用系统命令

小亿
101
2024-03-05 13:56:57
栏目: 编程语言

在Perl中调用系统命令可以使用system函数或者反引号操作符。下面是两种方法的示例代码:

  1. 使用system函数调用系统命令:
my $command = 'ls -l';
system($command);

在上面的示例中,我们使用system函数调用了ls -l命令来列出当前目录的文件和文件夹。

  1. 使用反引号操作符调用系统命令:
my $command_output = `ls -l`;
print $command_output;

在上面的示例中,我们使用反引号操作符调用了ls -l命令,并将输出存储在$command_output变量中,然后打印输出。

0