ikhan has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perlmonks
I am trying to read multiple sequential files and
writing to corresponding output files. My code
creates the output files but data is written to only
the first file
#!/usr/bin/perl use strict; use warnings; my $begin_flag=0; my $end_flag=0; my $blank_line=0; my $begin_count=0; for my $i (1.. 3) { open(my $file1, '<', "input_$i.txt"); open(my $file2, '>', "output_$i.txt"); while(my $line= <$file1>) { $begin_flag =1 if($line =~ /^x/); $end_flag =1 if($line =~ /^y/); if($begin_flag==1 && $end_flag==0 && $begin_count++ >0) { print $file2 $line if($line !~ /^\s*$/); } } close $file1; close $file2; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiple files to multiple files
by Corion (Patriarch) on Oct 18, 2015 at 07:05 UTC | |
|
Re: multiple files to multiple files
by Laurent_R (Canon) on Oct 18, 2015 at 09:57 UTC | |
|
Re: multiple files to multiple files
by bagyi (Acolyte) on Oct 18, 2015 at 07:26 UTC | |
by Laurent_R (Canon) on Oct 18, 2015 at 09:28 UTC | |
by afoken (Chancellor) on Oct 18, 2015 at 09:41 UTC | |
by Laurent_R (Canon) on Oct 18, 2015 at 09:49 UTC |