in reply to Using simultaneous threads
The only difference will be that $cmd won't end with a pipe |. Moreover, since you are running mysqldump, you can also use the -r option to direct output to the dump file instead of redirecting standard output. Indeed, this is better since then you can use the safer, multi-argument version of system.for my $db (keys %{$db_ds}) { ...figure out which table to dump, etc... system("$cmd > $dumpfile &"); }
If you need to wait for the mysqldump commands to finish, then it is just a little bit trickier:
for my $db (keys %{$db_ds}) { ...figure out which table to dump, etc... unless (defined(my $pid = fork)) { die "unable to fork: $!\n"; } if ($pid == 0) { exec("$cmd > $dumpfile"); die "unable to exec for table $table: $!\n"; } } # now wait for all the children to finish 1 while (wait > 0);
|
|---|