[Israel.pm] using "system"

Mikhael Goikhman migo at homemail.com
Sun Oct 31 05:15:46 PST 2004


On 31 Oct 2004 14:52:53 +0200, Tal Kelrich wrote:
> 
> On Sun, 31 Oct 2004 14:23:30 +0200
> Offer Kaye <offer.kaye at gmail.com> wrote:
> 
> > On Sun, 31 Oct 2004 11:28:30 +0000, Mikhael Goikhman
> > <migo at homemail.com> wrote:
> > > 
> > > Here is an example of both:
> > > 
> > >   system("ls", "-al");
> > > 
> > >   system {"ls"} "dir", "-al";
> > 
> > I think I get it - the "system PROGRAM LIST" format of the command is
> > just a way of "fooling" the program into thinking it is running as
> > "dir" while it is really running "ls"?
> 
> It's also useful for running programs with strange characters in the argument list, which may be interpreted by the shell otherwise. (as perl will not pass it through "/bin/sh -c", so no shell expansion will occur)

You speak about the system("ls -al") syntax that is indeed better to be
avoided. The first form above is preferable instead.

> I use this as my default form, as it is much safer than the alternative IMHO.

True, but it still does not explain why you may want to fiddle with
argv[0] of other programs as in the second example, and this is actually
what Offer wanted to know.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list