use strict ; use warnings ; use IPC::Open3 qw( open3 ) ; use MCE::Loop ; MCE::Loop::init { max_workers => 3, chunk_size => 10 } ; my $cmd = 'perl readfiles.pl' ; sub do_work { my @ar = @{$_[0]} ; my $id = $_[1] ; open( my $fho, ">", "output\\$id.txt" ) or die "Can't open > output\\$id.txt: $!" ; foreach ( @ar ) { print $fho $_ ; } close($fho) ; } my $pid = open3( undef, my $filedata, undef, $cmd, @_, ) ; print STDERR "Starting MCE loop\n" ; mce_loop_f { my ( undef, $chunk_ref, $chunk_id ) = @_ ; do_work( $chunk_ref, $chunk_id ) ; } $filedata ; print STDERR "Ended\n" ; waitpid( $pid, 0 ) ; warn "Failed\n" if ( $? << 8 != 0 ) ; close($filedata) ; #### use strict ; use warnings ; my @files = qw( data1.txt data2.txt data3.txt ) ; foreach ( @files ) { open( my $fh, "<", $_ ) or die "Can't open < $_: $!" ; while(<$fh>) { chomp; print $_ . "\n" ; } close( $fh ) ; } #### use strict ; use warnings ; open( my $fh, ">", "data1.txt" ) or die "Can't open > data1.txt: $!" ; for my $i ( 1..1000 ) { print $fh "$i\n" ; } close $fh ; open( $fh, ">", "data2.txt" ) or die "Can't open > data2.txt: $!" ; for my $i ( 1001..2000 ) { print $fh "$i\n" ; } close $fh ; open( $fh, ">", "data3.txt" ) or die "Can't open > data3.txt: $!" ; for my $i ( 2001..3000 ) { print $fh "$i\n" ; } close $fh ;