Perl qx Function



Description

This function is a alternative to using back-quotes to execute system commands. For example, qx(ls -l) will execute the UNIX ls command using the -l command-line option. You can actually use any set of delimiters, not just the parentheses.

Syntax

Following is the simple syntax for this function −

qx EXPR

Return Value

This function returns the value from the executed system command.

Example

Following is the example code showing its basic usage −

#!/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";

When above code is executed, it produces the following result −

176     /tmp
perl_function_references.htm
Advertisements