On 07/24/2018 08:35 AM, Lauren C. wrote:
Hi,

$ perl -le 'system "df -h"'

$ perl -le 'system "df","-h"'

The both two styles work fine.
what's the difference between them and which is better usage?

this is a more technical answer than the others but it may be useful to you or other readers.

when you call system with one string argument, it then calls the shell and passes that argument to the shell. the shell parses the string and does globbing (expanding * and such). perl just gets the results back from the shell and returns it.

if you call system with a list of arguments, it doesn't call the shell but it forks a new process directly and passes it the list of arguments in the standard way (argv style). so it is a more secure method as it can't be fooled by shell tricks. it is also faster as it doesn't need to fork a shell.

so both work in your example but they do very different methods of getting there. in your case it likely won't matter (other than the full path to the command issue someone posted).

uri

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to