Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl multiple perl files

Status
Not open for further replies.

sedawk

Programmer
Joined
Feb 5, 2002
Messages
247
Location
US
I have multiple *.pl file in a project. Can I perl them in one line as a multiple file C-project? e.g.,

perl file1.pl file2.pl ...
 
Are yuo trying to run two seperate processes in parallel?


Trojan.
 
Yes. In fact, there may be more than two processes.

Thanks
 
I don't think DOS can do that directly
I guess you might have to run a number of seperate DOS Prompt windows and run one process in each
Unless you redesign your perl to do all the processes at once.


Trojan.
 
If you run your Perl script in DOS the "normal" way, it will block until it finishes executing before DOS can accept another command, so you'll need to use "start" to start it as a new process, separate from the DOS window, e.g.

Code:
C:\script>start perl a.pl

C:\script>start perl b.pl

C:\script>start perl c.pl

Each Perl script will open a new console window though as if you double-clicked its PL file. If you don't want a console window, you can use wperl, just substitute it for "perl" in those commands (start wperl a.pl)... wperl doesn't use a console window, but you also won't be able to see its STDOUT, so if that's a problem you can send its output into a file through DOS.

Code:
C:\script>start wperl a.pl > a.txt

then all STDOUT and STDERR (or basically anything that'd be shown in a console window) from a.pl would go to a.txt

As an alternative, you can use threads and make it all one Perl process.

Code:
use threads;

my $a = threads->create (sub {
   do "a.pl";
});
$a->detach; # separate it from main thread

my $b = threads->create (sub {
   do "b.pl";
});
$b->detach;

Since your scripts would have run independently to begin with, threads should work fine in this case. But if they were going to interact with one another, you'd need threads::shared to share variables among them, since threads generally are their own Perl processes (as if you'd run wperl on all the different PL files and they all spawned as different processes)... just they're tied together in just one process.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top