in reply to Re: Running System Commans With ""
in thread Running System Commands With ""

The list argument form of system is also FASTER than the scalar form, isnt' it? I believe I read somewhere that the scalar form invokes another shell and hands off the processing to it, whereas the list form is more... er, direct? Faster and more secure. Mmmmmmm...

I can't explain how but I know I read it somewhere. Could someone elaborate for me about what the list form actually does?

--
perl: code of the samurai

Replies are listed 'Best First'.
Re: Re: Re: Running System Commans With ""
by jkahn (Friar) on Sep 11, 2002 at 20:26 UTC
    Yes, it's faster because there's no need for an intermediate sh process to get loaded, parse the arguments, redirect input and output where they should be sent to, and pass the arguments to the program invoked.

    If you do want shell-style redirection, though, you'll have to use a system EXPR syntax. It's not all bad; a number of Perl Cookbook recipes use it for good reason (mostly for shell redirection).

      Yes, it's faster because there's no need for an intermediate sh process to get loaded, parse the arguments, redirect input and output where they should be sent to, and pass the arguments to the program invoked.
      No, if there are no shell metachars, Perl does the splitting itself, so there's no sh process involved.

      Convince yourself of this by executing an appropriate ps command during each of

      system "sleep 5"; system "sleep 5;"; # notice the semicolon
      Other arguments in favor of "avoid the sh at all costs" in this thread are still valid. Just wanted to point out that the single-arg system does not always call sh. It just might.

      -- Randal L. Schwartz, Perl hacker