On Mon, May 25, 2009 at 4:30 AM, Robert Klemme
<shortcutter / googlemail.com> wrote:
>> Jagadeesh wrote:
>>>
>>> Hi,
>>> I am looking for something similar to join in perl. I am doing
>>> [sample perl code]
>>>
>>> $CMD = join(' , cmd, $arg1, $arg2, $arg3);

> Alternative approaches:
>
> str = "#{cmd} #{arg1} #{arg2} #{arg3}"
> str = sprintf '%s %s %s %s', cmd, arg1, arg2, arg3
>
> If this is for executing an external process, there is no need to lump
> all these together, instead you can do which has the advantage that
> you do not need a shell to parse the individual arguments and also
> whitespace cannot cause trouble.
>
> system cmd, arg1, arg2, arg3

Well sometimes it's an advantage, but it's more of a difference
between a single and multiple string arguments to Kernel#system

If you WANT the shell to parse the cmd then you want a single string.
Of course you also need to be aware of the security aspects when you
use an unsanitized string coming from user input, rather than one
you've had more control over.

-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale