perl
Runs a Perl script and returns its output and exit status.
Category: Environment and Settings > System Commands
Syntax
[result, status] = perl(scriptfile)
Runs the script and returns what it printed and its exit code.
[result, status] = perl(scriptfile, arg1, ..., argN)
Passes the arguments to the script on its command line.
Description
perl is a thin wrapper over the system Perl interpreter. It calls perl scriptfile args and captures the output as a character vector. A Perl installation must be available on the machine; it is not bundled.
Input arguments
scriptfile- Path of the Perl script. A file that does not exist is an error.
arg1, ..., argN- Character vectors passed as command-line arguments.
Output arguments
result- Text the script wrote to standard output.
status- Exit code of the interpreter;
0means success.
Example
Run a one-line script
fid = fopen('hello.pl', 'w');
fprintf(fid, 'print "hello from perl\\n";');
fclose(fid);
[result, status] = perl('hello.pl');
disp(strtrim(result))
disp(status)
delete('hello.pl')
Output
hello from perl
0