in reply to Can I run a piece of code like child process?

Use fork anyways. It is more efficient than you think.

See Threads vs Forking (Java vs Perl) and subsequent discussion (particularly the article that KM pointed out).

And don't use threads if you care about reliability, stability, and all that. Perl's threading does...interesting things.

  • Comment on Re: Can I run a piece of code like child process?

Replies are listed 'Best First'.
Re: Answer: Can I run a piece of code like child process?
by =sjs= (Initiate) on Nov 08, 2001 at 22:45 UTC
    The short answer is yes. But it really depends on what you're doing as to whether it makes sense to. #!/usr/local/bin/perl my $string = "print \"hello\\n\";"; if (fork() == 0) { system "perl -e '$string'"; }