[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] seperate large file into smaller files



hello,
i have an extremly large text-file
(0.5GB). this file is probably about
50.000 lines long.
instead of opening the whole file in an
editor i want perl to seperate the file
into smaller files and each of these files
should be 1000 lines long.
i'm stuck with the script below which
indeed will create the relevant files but
will only contain their corresponding
linenumbers.
for instance a file created called
2000.txt will contain only the text from
line number 2000 from the hit.txt-file
when it should instead contain all text
from the lines 2000 to 2999




#!perl -w

$file = "hit.txt";
open (FILEHANDLE, $file) or die $!;
$lines= 0;
divide_files();

sub divide_files {
 while (<FILEHANDLE>) {
  if ($. >= $lines && $. < $lines+1000) {
   open (NEWFILES, ">$lines.txt") or die
$!;
   print NEWFILES $_;
   $lines += 1000;
   divide_files();
  }
 }
}



==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org