Here's a simple solution that can use if:
- your perl program doesn't need to process the output of mysqldump as it is being generated, and
- you don't need to wait for the mysqldump commands to finish
If both of these are true, then structure your code like this:
for my $db (keys %{$db_ds}) {
...figure out which table to dump, etc...
system("$cmd > $dumpfile &");
}
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.
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);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.