in reply to Re: Variables loop in Parallel::ForkManager
in thread Variables loop in Parallel::ForkManager

Thank you but it doesn't work...Maybe I'm doing something wrong : #!/usr/bin/perl use Parallel::ForkManager; my $pm = new Parallel::ForkManager(3); my @y; { open my $fh_y, '<', 'y' or die $!; chomp( @y = <$fh_y> ); } open(my $fh_x, '<', 'x') or die $!; while (<$fh_x>) { $pm->start and next; chomp( my $linex = $_ ); open my $fh_out, '>', $linex or die $!; for (@y) { print $fh_out ("$linex$liney\n"); } $pm->finish } When I perl script.pl it gives me the 5 "$filex" files but like this : jacky@ubuntu:~/Desktop/test$ cat 1 1 1 1 So definatelly there is something wrong in there...Thank you again

Replies are listed 'Best First'.
Re^3: Variables loop in Parallel::ForkManager
by ikegami (Patriarch) on Nov 29, 2008 at 23:50 UTC
    for (@y) should be for my $liney (@y)
      Thank you,but :D it still doesn't work I did what you said but now it gives me the files like this : jacky@ubuntu:~/Desktop/test$ cat 1 1jack 1john 1joe jacky@ubuntu:~/Desktop/test$ cat 2 2jack 2john 2joe And so on...Any fix to this too? , Jack

        The following might help. I don't understand why you are forking, so I have not done so, but you could add forking inside the loop if you want to, as long as you increment and reset $index_y in the main process so that it is coordinated across all the child processes.

        #!/usr/bin/perl use strict; use warnings; open(my $y, "<", "y") or die "y: $!"; my @y = <$y>; close($y); my $index_y = 0; open(my $x, "<", "x") or die "x: $!"; foreach (<$x>) { chomp; open(my $output, ">", "$_") or die "$_: $!"; print $output "$_$y[$index_y]"; close($output); $index_y++; $index_y = 0 if($index_y > $#y); } close($x);
        That's my understanding of what you wanted. What output do expect from cat 1 and cat 2?