5 use warnings qw< FATAL all >;
7 use Scalar::Util qw< openhandle >;
11 my $fh = new IO::Handle;
16 while ($line = <STDIN>) {
18 print STDERR "DEBUG: Reading '$line'\n" if $debug;
19 if ($line =~ /^(\d+)$/) {
21 $filename = "$section.txt";
22 print STDERR "DEBUG: Starting section $section\n" if $debug;
23 close $fh if $fh->opened();
24 open ($fh, ">>$filename") or die "Couldn't open file $filename, $!"
27 # Print to the file if we have a filehandle except for the
28 # section number itself
29 if ($line !~ /^(\d+)$/) {
30 if ( $fh->opened() ) {
31 print STDERR "DEBUG: Printing to $filename\n" if $debug;
32 print $fh $line."\n" ;
38 close $fh if fileno($fh);