So you want to set the file boundary to just before "INPUT SEQUENCE"?

There Is More Than One Way To Do It - one bizarre way is

#!/usr/bin/perl { local $/ = "INPUT SEQUENCE="; <>; # discard first chunk while(<>) { chomp; open O, '>', /^(\d+)/ and $1 or die "$!\n"; print O $/,$_; } }

update - oh. You want bunches of 1000 records in separate files?

#!/usr/bin/perl { my $file = 'File00000'; local $/ = "INPUT SEQUENCE="; <>; while(<>) { chomp; unless ($.-2 % 1000) { open O, '>', ++$file or die "cant write '$file': $!\n"; } print O $/,$_; } }

update - a bit of explanation: setting the input record separator $/ (see perlvar) to the token right after the file boundary lets the diamond operator <> (or readline) read up to and including that token as a single line into $_.

With chomp we remove $/ from the end; it is added up front when outputting. The ++$file is a string increment; doing that we get the next file name (File00001, File00002, ... ).

Since the first "line" (consisting of the record separator only) isn't interesting, we do a <> before the loop. Next line is then number 2 ($. - see perlvar), and $.-2 % 1000 (modulo 1000) is 0 at line 2, 1002, 2002, ... , so we (re-)open the output filehandle at that line count, which does an implicit close. See open.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: split of files by shmem
in thread split of files by boby

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.