====== splitre.pl ======

<code perl>
# splitre.pl -- Split file on specified regexp
# 2010/6/19 David Meyer papa@freeshell.org

$re=shift;
$fext=shift;

$fn=0;

open OUT, ">".sprintf("%03d", $fn).".$fext";

while (<>) {
    print OUT $_;
    if ($_ =~ /$re/ ) {
	close OUT;
	open OUT, ">".sprintf("%03d", ++ $fn).".$fext";
    }
}
</code>
{{tag> perl}}
Category: [[perl:]]

~~LINKBACK~~
~~DISCUSSION~~