Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the difference between backquotes (``) and system in perl

Shulou Source: shulou.com Published: 2022-06-01 13:02:37 09月27日 Update

This article mainly shows you "what is the difference between backquotes (``) and system in perl". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the difference between backquotes (``) and system in perl".

Backquotes (``) and system are both ways of executing system commands in perl, but they are quite different. Generally speaking, in the perl program, "`$cmd`" gets the result of the program execution, while system ($cmd) gets the return value after the program execution. For more information, please see the following example:

Demo example:

#! / usr/bin/perl use strict;my ($cmd,$ret1,$ret2); $cmd = "ls / tmp"; print "* execute backquote result *\ n"; $ret1 = `$ cmd`; print "* execute system result *\ n"; $ret2 = system ($cmd) Print "* backquote mode *\ n"; print $ret1; print "* below is system mode *\ n"; print $ret2

The implementation results are as follows:

[root@mdw ~] # perl 20150325.pl* execute backquotation mark result * # backquote execution result output is empty * execute system result * # system output execution result dsp.waredsSvc.wargconfd-rootkeyring-ap4Ph9* * backquotation mark mode * dsp.waredsSvc.wargconfd-rootkeyring-ap4Ph9* below is system mode * 0 [root@mdw ~] #

As can be seen from the above execution result, when the system command is called, the system outputs the execution result to the screen and passes the return value (0 or non-0) of the execution result to $ret2

However, backquotation marks (``) will save all results to the variable $ret1 and will not output any results.

The above is all the content of this article entitled "what is the difference between backquotes (``) and system in perl? thank you for reading!" I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Results quotation marks ways different output between content programs articles commands examples systems learning help large variable screen overall time easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Tech Info NVidia macOS OPPO Reno