This code snippet will hopefully help you. It reads lines and stores them into an array until the token 'TIMESTEP' is found. Afterwards, the array is iterated and each element is written to the appropriate file. Since you did not supply a data file, i will with the help of our friends from 'Mr. Show'. Here they are, doing Shakespeare:

output.txt:
I'm the king! 
I'm mad! 
I want the news from my kingdom! 
TIMESTEP
I'm the queen! 
Blah blah blah! 
Look at me!
TIMESTEP
Your majesty, I'm a clown or something.. 
I've got makeup on my face, 'cause my mommy and daddy didn't 
give me enough attention!
TIMESTEP
I'm a big actor! 
Look at the great big actor on the stage! 
I yell the loudest!
Look at me!
TIMESTEP
Oh mighty king! 
We are your sons! 
We're loud, stupid actors and we're gonna have a big dumb 
sword fight, in your honor!
TIMESTEP
And here is the script:
use strict; my @superchunk; # i think i'm hyper enough as it is ... my $i = 0; open(IN,'output.txt') or die $!; # process one line at a time # add each line to the element that $i is # increment $i when TIMESTEP is encountered while (<IN>) { $superchunk[$i] .= $_; $i++ if /^TIMESTEP/; } close IN; $i = 1; # process one element at a time # use sprintf to create the name of the file # write that element to the file for (@superchunk) { my $file = sprintf("%s%02d%s",'BRO',$i++,'.pdb'); open(OUT,">$file") or die "can't write to $file: $!"; print OUT $_; }
After you execute this script, you will have 5 files: BRO01.pdb, BRO02.pdb, BRO03.pdb, BRO04.pdb, and BRO05.pdb. Read up on sprintf for more info about that highly useful function.

Final thought, instead of storing the lines to be written in an array, consider writing them out inside the while loop instead. This works better for very large files, but if you have plenty of RAM then storing them in an array first should be OK.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Redone DB split help needed by jeffa
in thread Redone DB split help needed by Brokensoulkeeper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.