There are many ways to crack this problem. This technique changes the line separator to be two new lines:

use strict; use warnings; my $filename = "MyFileName0000"; local $/ = "\n\n"; while (<DATA>) { chomp; ++$filename; print "**** Open file $filename here\n"; print "$_\n"; print "**** Close file $filename here\n"; } __DATA__ CREATE TABLE sec_afs ( rpt_per_typ_c char(1) NOT NULL, rpt_per_typ_t varchar(20) NULL, LOCK ALLPAGES go EXEC sp_primarykey 'sec_afs', rpt_per_typ_c go GRANT SELECT ON sec_afs TO developer_read_only go CREATE TABLE dbo.sec_iccc ( user_nt_id_c char(16) NOT NULL, unit_id_c char(4) NOT NULL ) LOCK ALLPAGES go GRANT SELECT ON sec_iccc TO developer_read_only go CREATE TABLE sac_recon( rec_number int NOT NULL, rec_grp_number int NOT NULL, ) go

Prints:

**** Open file MyFileName0001 here CREATE TABLE sec_afs ( rpt_per_typ_c char(1) NOT NULL, rpt_per_typ_t varchar(20) NULL, LOCK ALLPAGES go EXEC sp_primarykey 'sec_afs', rpt_per_typ_c go GRANT SELECT ON sec_afs TO developer_read_only go **** Close file MyFileName0001 here **** Open file MyFileName0002 here CREATE TABLE dbo.sec_iccc ( user_nt_id_c char(16) NOT NULL, unit_id_c char(4) NOT NULL ) LOCK ALLPAGES go GRANT SELECT ON sec_iccc TO developer_read_only go **** Close file MyFileName0002 here **** Open file MyFileName0003 here CREATE TABLE sac_recon( rec_number int NOT NULL, rec_grp_number int NOT NULL, ) go **** Close file MyFileName0003 here

Update: Note cdarke's++ improvement of using "" to get 'paragraph' behavior.


Perl reduces RSI - it saves typing

In reply to Re: split one file into many on finding a new line by GrandFather
in thread split one file into many on finding a new line by smarter_aries

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.