Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report