As personal preference I do try hard not to use system() calls in my Perl 
scripts because Perl can do everything itself with built-ins or 
modules.  It's my opinion that while easier in terms of coding a lot of the 
time using system() calls or back-tics it is harder, albeit most likely not 
too much, on the host machine to call outside programs to perform certain 
functions.  So, I avoid doing so as often as I can.

Therefore, use the built-ins.  To do file manipulations use File::Copy 
which gives the ability to move(), copy() files.  Use Cwd.pm to get current 
working directory (getcwd()), and use use chdir() to change directory.  You 
can use perldoc File::Copy, perldoc -f chdir, and perldoc Cwd to get 
documentation on these functions.

So, I agree with Peter in his last couple of paragraphs and put my 2 cents 
in that imho, it is better to use perl built-ins as much as possible.

- Jim

At 07:30 12.23.2001 -0800, Peter Cornelius wrote:
>There are several methods for executing external commands from Perl.  The 2
>most common would be 'system()' and backticks '``'.  You should probably
>read the 'perldoc -f system' for detailed info.  The main difference between
>backticks and system is where the commands output goes and where the return
>value goes.  With system the output is not redirected for you and the return
>code goes to $!.  With backticks the output is returned to the program and
>the return code goes to $?.
>
>You should probably try 'perldoc -q backtic' to get more info on this whole
>topic.  perlfaq8 has this to say.
>
>        What's wrong with using backticks in a void context?
>
>        Strictly speaking, nothing.  Stylistically speaking, it's
>        not a good way to write maintainable code because
>        backticks have a (potentially humongous) return value, and
>        you're ignoring it.  It's may also not be very efficient,
>        because you have to read in all the lines of output,
>        allocate memory for them, and then throw it away.  Too
>        often people are lulled to writing:
>
>            `cp file file.bak`;
>
>        And now they think "Hey, I'll just always use backticks to
>        run programs."  Bad idea: backticks are for capturing a
>        program's output; the system() function is for running
>        programs.
>
>There's more but I wont repost it here.
>
>All this being said, you should probably look into how perl could do most of
>these things for you without using the shell.  The 'cd' shell command is
>built in with 'chdir'. perldoc -f chdir reads
>
>         chdir EXPR
>               Changes the working directory to EXPR,
>
>and the cp stuff is in a module called File::Copy
>This is a standard module that you can get at by putting
>use File::Copy;
>
>at the top of your script.  Then somewhere you can
>copy ("source", "dest") or die "with a useful message: $!\n";
>
>Guess what I'm going to say next?  perldoc File::Find will tell you more.
>
>Good luck,
>Peter C.
>
>--SNIP--
>Hello all,
>   I'm writing a common gateway interface that will call I need to
>issue several shell commands.
>(cp, cd, and cd .., and maybe others). Any assistance would be
>greatly appreciated. How can a call a shell other than bash.
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]


- Jim

Philosophy is for those who have nothing better to do than wonder
why philosophy is for those who have nothing better to do than...




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to