Hi PerlMonks, I'm working to create a loop that will read all text (.txt) files in a directory, excluding any sub-directories. Simple enough, think I have the pattern match, but not enough knowledge to incorporate it into the IF or NEXT UNLESS condition. Once the files are read, I'm hoping to strip HTML tags with HTML::STRIP. I am grateful for any insight you may have. Here is the code I am working with:
#! /usr/bin/perl -w use strict; use warnings; use lib "c:/strawberry/perl/site/lib"; use HTML::Strip; my $hs = HTML::Strip->new(); my $write_dir = 'G:\research\sec filings 10k and 10Q\data\filing docs\ +1993\Clean'; my $files_dir = 'C:\Dwimperl\Perl\1993'; opendir (my $dir_handle, $files_dir) || die "failed to open '$files_di +r' <$!>"; while (my $file = readdir($dir_handle) ) { next if $file eq '.' or $file eq '..';# or $file =~ /[0-9|-]+\.txt +$/; open my $file_handle, "/dwimperl/perl/1993/$file" or die "failed t +o open '$file' <$!>"; foreach my $line (<$file>) { my $clean_text = $hs->parse( ' ' ); print $write_dir "$file\n"; $hs->eof; } } close(); closedir $dir_handle;
In reply to Read files not subdirectories by wrkrbeee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |