line1 data data data
line2 data data dataline3 data data data
line4 data data data
line5 data data data
line6 dataline7 data data data data
line8 data data data data
####
use strict;
use warnings;
use GRID::Cluster;
my $script = "script.plx";
my @processes = (...);
my @machines = (...);
my %max_num_processes = (...);
my $cluster = GRID::Cluster->new(
host_names => \@machines, max_num_np => \%max_num_processes,
);
$cluster->qx(@processes);
####
use strict;
use warnings;
use Fcntl qw(:flock);
my @letters = qw(a b c d);
foreach my $letter (@letters) {
my $output_file = "output_" . $letter . ".txt";
# This didn't solve my problem
# I also tried +< instead of >>, but nothing happened at all
# when I did that
# open my $filehandle, ">>$output_file";
# flock($filehandle, LOCK_EX);
# So instead I tried the version in the comments on the
# tutorial page although I don't really understand it :-(
open my $semaphore, ">$output_file.lock";
flock($semaphore, LOCK_EX);
open my $filehandle, ">>$output_file";
print $filehandle "line$number data data data\t";
close $filehandle;
close $semaphore;
}