#!/usr/bin/perl -w # # mlt file spliter # # ./split.pl file_name.mlt [prefix] # # use strict; use warnings; use utf8; use File::Basename 'fileparse'; use File::Spec; use NKF; my $file = $ARGV[0]; my $prefix = $ARGV[1] ? $ARGV[1] : ''; my ($basename, $dirname, $ext) = fileparse($file, qr/\..*$/); my $dir = $basename; if (! -d $dir) { mkdir ($dir); } open( my $in, $file) || die "$!"; my $list_file_name = File::Spec->catfile($dir, '_list.html'); open(LIST, ">" . $list_file_name) || die "$!"; my $header_html = <<"EOD";
EOD print (LIST nkf('-w', $header_html)); my $count = 0 ; my $skip = 0; my $buf; my $pattern = nkf("-w" , "^(【.*】|最終更新日)"); while( <$in> ) { $_ = nkf("-w -x --ic=CP932", $_); if (/$pattern/) { $skip = 1; } elsif (/^\[SPLIT/) { if ($skip != 1) { $count += 1; my $output_file_name = File::Spec->catfile($dir, $prefix . $count . '.txt'); open(OUT, ">" . $output_file_name) || die "$!"; print(OUT $buf); close(OUT); my $brbuf = $buf; $brbuf =~ s/\n/