I always use the list form of system, which allows me some flexibility, such as ignoring shell escapes. However, to see what I'm running I often sprinkle this in my code. It's not intended to create something you can run at the shell (although it probably does so most of the time), just to give me an idea of what the heck I'm really running, in case it looks completely wrong.
The problem always is that when I have embedded spaces, I can't tell where there is the change between command arguments vs a single argument with those spaces. Data::Dumper could work, but that would just be difficult to read. Here's a compromise - putting single quotes around anything with spaces, and escaping single quotes within it. Not perfect, but close enough given that you're not supposed to pass this to the shell.
print join(" ", 'Command:', map { my $x = $_; if (/\s/) { s/'/\\'/g; " +'$_'" } else { $_ } } @cmd), "\n" if $ENV{'VERBOSE'};
In reply to Debugging a system command by Tanktalus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |