in reply to Splitting long file

Untested:
open BIG, 'big_file'; my $i = 1; while (<BIG>) { open OUT, ">outfile_" .$i++; #BUG: see follow up below. if ( m/^\$\n$/ ) { close OUT; open OUT, ">outfile_" .$i++; next; } print OUT; } close OUT;
Doesn't deal with your naming but that should be easy to add.

PS. if you intend to create 22000 files you should probably put them into subdirectories, not all in one directory.

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re: Re: Splitting long file
by matija (Priest) on Apr 08, 2004 at 11:39 UTC
    Since you are reading line by line, the
    if ( m/^\$\n$/ )
    will never match.
    Update: I am an idiot. This will hopefully teach me to pay closer attention to which $ is meant as end of line, and which is meant as literal $. (And I will start using \z in my regexps...)
      It does work because I have not chomped the line.

      However the second open is in the wrong place:

      ### WRONG ### while (<BIG>) { open OUT, ">outfile_" .$i++; if ( m/^\$\n$/ ) { ### CORRECT ### open OUT, ">outfile_" .$i++; while (<BIG>) { if ( m/^\$\n$/ ) {

      --tidiness is the memory loss of environmental mnemonics