title: How to use fork() in Perl?
body: <p>I have hundreds of file names in an array. I want to create a child process for every 4 files in the array, and have that child do some stuff to each of those 4 files. (So with 100 files, I'll create 25 processes.)</p>
  
  <p>I'm having some trouble understanding the order in which lines are processed when there's a fork. I was thinking I could do something like this, but I'm getting stuck:</p>
  
  <pre><code>foreach $file (@files) {
   if ($f++ % 4 == 0) {
    my $pid = fork();
  
    if ($pid) {
     push(@childs, $pid);
    }
    elsif ($pid == 0) {
      ... do stuff to $file ...
    }
   }
  </code></pre>
  
  <p>I don't think this is right, and I'm hoping someone can point me in the right direction. Thanks.</p>