This is probably the simplest approach:
$/ = 'XXFFDDF'; # set the input record separator
my $base = 'filename';
my $i = 0;
while (<>) { # read one section at a time
my $filename = "$base$i"; # generate a new filename
open(OUT, ">$filename") # create and write a new file
or die "Can't open $filename: $!\n";
print OUT;
$i++;
}
You can generate the filenames however you prefer. I just chose a very simple way of generating the names as an example.
If each section is very long, you might want to read the file in in smaller chunks to conserve memory.
One final note: this puts the XXFFDDF at the end of each file. If you want to put it at the beginning, the code will need to be somewhat different.
|