sans-clue has asked for the wisdom of the Perl Monks concerning the following question:

If I have a while loop in which I call a subroutine, is there is way to 'nohup' it ? Sorry I don't know the correct terminology.
sub foo { sleep(60); print "foo\n"; } my $p = 50; while ($p > 5){ sleep(5); print "bar\n"; &foo; # do not wait for return please }
Is it possible that "bar" can be printed approx every 5 secs while "foo" approx every 60 ? I'm not actually printing of course, but I need this logic to work. Thanks

Replies are listed 'Best First'.
Re: Run a subroutine in the background ?
by BrowserUk (Patriarch) on Nov 05, 2009 at 01:42 UTC
    use threads; ... async \&foo; ...

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Run a subroutine in the background ?
by llancet (Friar) on Nov 05, 2009 at 02:00 UTC
    Logically, you are going to do two things at one time, so you should see:
    threads threads::shared
    or
    fork()