merlyn, thanks for pointing out how to force list interpretation for system.

I think my /bin/foo bar example was a red herring. A better example of what I would like to see perl discourage is the the following use of system to execute a single command:

system("cmd $with $some $args")
Because the argument is subject to shell interpretation, this code exposes itself to just too many pitfalls. If we saw this in someone else's code we'd clearly point out that it's unsafe.

If you really want to subject your string to shell interpretation, why not just explicitly call the shell?

It's good that perl provides a way to force list context with system. However, I'll argue that it isn't getting used when it needs to. Users are introduced to this:

system("/bin/ls"); # run /bin/ls with no arguments
and they generalize to:
system($cmd); # run the $cmd command with no arguments
not:
system {$cmd}, $cmd;
Even when we tell them to use the list version of system to safely preserve passed arguments, they can be in for a surprise. They see this:
system($cmd, $with, $some, $args);
and generalize to:
system($cmd, @args);
and then wonder why it doesn't work as expected when @args is the empty list.

In reply to Re: Use of system() considered harmful by pc88mxer
in thread Use of system() considered harmful by pc88mxer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.