in reply to splitting a large text file and output
This should be readily adaptable to your schema of variable names and filenames. Please note, it's not valid for interactive input, so don't use it with <>, just to be safe. If you needed to take input from <> you should remove the eof() test, and instead print to one last file after the while loop expires. If you end up doing that, put your output code into a separate subroutine to avoid code duplication.
my @output; my $outfile_name = "Outfile0000"; while ( <DATA> ) { chomp; push @output, $_; if( /VECT/ or $. % 12 == 0 or eof(DATA) ) { open my $out_fh, '>', $outfile_name++ or die $!; say $out_fh $_ for @output; @output = (); close $out_fh or die $!; } }
Dave
|
|---|