This is part of my very nasty code for printing the right stuff for one VP, but it is highly useless for the entire fileNo, you almost have it (at least if I understood correctly what you want to do). Your code is reading the file line by line, which is what you need. For each line, you just need to pickup the relevant fields and print them out.
You only need to open a new output file for each input record.
You did not say how you want to name your files, so I will pick up the first field as it seems to be a line number.
I do not understand, though, why you are splitting the data into fields and then join them back into the original format before printing it. So this could be simply:while (<REIN>) { chomp(); my @we = split(/\t/); my $out_file_name = "out_file_nr_$we[0]"; open my $RAUS, ">", $out_file_name or die "could not open $out_fil +e_name $!"; my $fix = "$we[0]\t$we[1]\t$we[2]\t$we[3]"; my $out1 = "$we[4]\t$we[5]\t$we[6]\t$we[7]\t$we[8]\t$we[9]\t$we[10 +]\t$we[11]\t$we[12]"; print $RAUS $fix ."\t" .$out1."\n"; close $RAUS; } close(REIN)
Or did I miss something in your requirement?while (<$REIN>) { my $out_file_name = "out_file_nr_[$.]"; # $. is the line number on + the last read file handle open my $RAUS, ">", $out_file_name or die "could not open $out_fil +e_name $!"; print $RAUS $_; close $RAUS; } close(REIN)
In reply to Re^3: Spliting Table
by Laurent_R
in thread Spliting Table
by tschelineli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |