私は完全なn00bです。このサイトの他の多くの投稿を読みましたが、この比較的単純な問題の解決策を見つけることができませんでした。基本的に、HTML でマークアップされたテキスト ファイルのディレクトリがあります。このディレクトリ内の各ファイルから HTML を取り除き、個々のファイルを新しいテキスト ファイル (できれば _out.txt 拡張子を使用) にエクスポートしたいと考えています。これが私がこれまでに試したことです:
use strict;
use warnings;
use File::Find;
use HTML::FormatText;
my $root_path=qq{C:\\Filings\\test}; #Declare your input path
# Recursively it process all the sub directories in $root_path
find(\&process_multiple_dir, $root_path);
sub process_multiple_dir
{
if (-f && $File::Find::name =~ m{\.txt$}) # It process .txt format files only
{
undef $/; # Input Record separator
# Files Handling process
open (FIN, "<$File::Find::name") || die "Cannot Open the Input file";
my $file=<FIN>; # Assign the file handler to scalar variable
#print $file;
my $string = HTML::FormatText->format_file($file,leftmargin => 0, rightmargin => 50);
#print $string;
close (FIN);
# Change the file name for the output file creation purpose
$File::Find::name=~ s{\.txt}{_Out.txt};
# Print the $file contents to new file
open (FOUT, ">$File::Find::name") || die "Cannot Create the Output file";
print FOUT $string;
close (FOUT);
}
}
このコードは、新しいファイル名 (タグ付けされた _out.txt 拡張子) を持つファイルを出力しますが、新しく作成されたファイルにはテキストが含まれていません...
ありがとう!