[Pdx-pm] sanity check: how to use system()

Eric Wilhelm ewilhelm at sbcglobal.net
Mon Feb 28 22:03:34 PST 2005

What's the deal with this bit of code:

  unless(system(join ' ', @command) == 0) ...


I've been digging through a lot of backup programs this week and have 
been driven at-least-insane by the number of times that I've seen 
something like $cmd .= $options;  system($cmd).  Particularly, this one 
makes me really have to hope that $dir and $count are never both equal 
to "/"

  system("$rm -rf $dir.$count")

I've checked "perldoc -f system | head -1" several times today and it 
still says:

  system LIST

And further down, there's lots of yummy detail about how calling it with 
a single scalar fires-up a shell and hands-off the command rather than 
the more efficient and less-subject-to-interpolation direct hand-off to 
execvp().  So, I'm evaluating these programs that are going to be run 
as root and keep having to wonder if they've caught all of the corner 
cases of special characters, spaces in filenames, and other such 

Then, I come across the above needless join of a perfectly LISTlike 
@command and I think I surely must have lost it.  Is there a historical 
reason or something here that I'm missing?

Rule out stupidity, then look for the simplest explanation. 
                                           -- Eric's Cleaver

More information about the Pdx-pm-list mailing list