Tony1 has asked for the wisdom of the Perl Monks concerning the following question:

hello monks
#!/usr/bin/perl -w ` cp /home/sankari/sample.pl /home/sankari/sample1.pl `; system "cp /home/sankari/sample.pl /home/sankari/sample3.pl";
can anyone explain me what's the different between use of the symbol backquote and system command in perl programming thanks in advance
  • Comment on difference bteween using back quote and sytem command in perl programming
  • Download Code

Replies are listed 'Best First'.
Re: difference bteween using back quote and sytem command in perl programming
by Zaxo (Archbishop) on Mar 28, 2007 at 07:09 UTC

    Backquotes return whatever the called program printed to STDOUT. System returns just the exit status.

    Your examples don't do anything with the return value. If that's intended, system should be preferred. You can check for errors in either function by looking at $? , the CHILD_ERROR variable.

    After Compline,
    Zaxo

      Yes, the handy thing with qx// is you can save the output to an array of lines @L = qx(cksum *);

      print pack "H*", "6772656574696e67730a"
Re: difference bteween using back quote and sytem command in perl programming
by GrandFather (Saint) on Mar 28, 2007 at 07:36 UTC

    See the documentation for system and the qx// operator in perlop (search for qx/STRING/ in the 'Regexp Quote-Like Operators' section. The major difference is that backticks allow you to capture the output from the command whereas system is a "launch and forget" process.


    DWIM is Perl's answer to Gödel