Parallel processing of XML files

I currently have an application that uses XML :: Twig and parses 20 XML files. Each file is 0.5 GB, and processing is performed in a sequential manner:

foreach (@files) {  
    my $ti = XML::Twig->new( 
        keep_encoding => 1,
        twig_handlers => {
            'section' => sub { $_->purge(); }
        }
    )->parsefile($_);
}

Is there any way with perl to run this code in parallel, and if so, how can I do this? My application runs on a Windows system.

+4
source share
1 answer

Parallel:: ForkManager CPAN. ( ) . , , Perl 5 threads, , , .

, , . , , , ( ) , , :

use Parallel::ForkManager;

$pm = Parallel::ForkManager->new($MAX_PROCESSES);

foreach $data (@all_data) {
  # Forks and returns the pid for the child:
  my $pid = $pm->start and next;

  ... do some work with $data in the child process ...

  $pm->finish; # Terminates the child process
}

, WINAPI Windows, ( Parallel:: ForkManager, , Windows, ). Perl Win32:: API CreateProcess() Perl ( ). Forks:: Super , Windows.

+2

All Articles