I am new to the perl fork function, and I am not sure that it does what I am looking for.
I have 2 long running subs. Sub1 I only want to run serially, sub2 I would like to fork off and not wait for a return. Here is psuedocode to illustrate (in my current implementation that has no forking):
#! /usr/local/bin/perl
use Mod1;
use Mod2;
my @nodes = ("switch1", "switch2", "switch3", "switch4", "switch5");
foreach my $node_name (@nodes) {
# a 4-10 minute TL1 conversation using Expect
my $port_hashref = Mod1->sub1($node_name);
# a five minute series of SQL queries using DBI
Mod2->sub2($node_name, $port_hashref);
}
I do not want to wait for sub2 to finish on a switch name before moving on to sub1 on the next switch name. I do not care about a return value from sub2.
With my limited understanding of fork, I expect it will fork the entire program instead of my sub2 code block and that it won't be easy to pass in my hash ref to sub2 after the fork.
Any ideas on how to do this (with or without fork)?
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.