Take a look at threads. If you are using AS, then the threads module is locate under the "Pragmas" section of the "Table of Contents" in the left-hand frame of the html docs.

If all you want to do is run the sub standalone to completion, then that is as simple as

use threads; sub YourSub { ... return $result; } ... my $thread = threads->new( \&YourSub, $arg1, $arg2, ... ); # If your not interested in the result from the sub then # $thread->detach; .... # Otherwise, this will retrieve the return value. # Note: This will block until the thread finishes. # One (of several) things missing from the API as it stands # is any way to determine if the thread has finished # without blocking. my $result = $thread->join;

If you need to communicate between your main code and the subs whilst it is running, then life gets a little more complicated.

If you give a clearer picture of what the sub is going to be doing (like the code:), then it may be possible to give a better example.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.


In reply to Re: Create a separate process with a sub... by BrowserUk
in thread Create a separate process with a sub... by Foggy Bottoms

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.