tags:

views:

128

answers:

2

Scenario 1: I have one wrapper Perl script which uses another Perl module and invokes a function in that module.

Scenario 2: Now I have the same wrapper script and the module is implemented as Perl script. Here, instead of using module I am simply calling system("perl anotherscript.pl").

Both do the same function, but I am seeing a little bit delay in the second scenario.

Why is it so? Is it expected or is it something to do with my code?

+10  A: 

In the first situation, you have the overhead of the Perl interpreter. In the second, you have the overhead of two Perl interpreters. If you want the second approach, consider an alternate and little-used version of the do function (see perldoc -f do):

do './anotherscript.pl'

If the Perl interpreter is designed at all well (and it probably is), this will probably run significantly faster than the second example, though I don't know how it will compare to the first one. If you want efficiency, benchmark.

EDIT: If you don't care about the (probably insignificant) performance difference between the two, I recommend you just use a module. It will make your code infinitely more useful, because while a script can only be re-used in one piece, modules can be re-used in as many separate pieces as you like.

Chris Lutz
use module and do '/path/to/file' do different things in general. Just want to make that clear!
derobert
thanks for the suggestion.. then i will go with perl module itself..
Anandan
@derobert - I think he knows that already, since he has working programs using each method. But definitely, they do quite different things.
Chris Lutz
i was not aware of "do" could do something other than do - while.. thanks for pointing me that out :)
Anandan
@Anandan - Neither was I for quite a while. Perl's documentation, both online and via the `perldoc` program, is excellent.
Chris Lutz
+1 for that last paragraph.
innaM
+1  A: 

You can have a module and a script at the same time by creating modulinos.

brian d foy