Hi!
I need to read text files from a directory and do some operations on all the files at once. This in order to get frequency counts for words over all files. Any guesses to why this code is not working?
The error message is: "Cannot open 'C:\Doc...\*.txt' Invalid argument at line 12"
While reading from each file, I would also like remove punctuation marks, s.a ". , ; : ? !" etc and write the output in the same file as I read from. Any ideas on how to do that?
Best,
lillyth.
#!/usr/local/bin/perl -w
use strict;
use lib 'C:\Documents and Settings\Usr1\Desktop\L';
use Lingua::EN::Tagger;
open (OUTFILE, '>>terms.txt'); # output file
@ARGV = 'C:\Documents and Settings\Usr1\Desktop\L\textFiles\*.txt';
my $tagged_text = '';
my $p = new Lingua::EN::Tagger;
while (<>) {
while(<$_>){
my $temp = $p->add_tags( $_ );
$tagged_text = $tagged_text. $temp ;
}
}
my @word_list = $p->get_words( $tagged_text );
foreach my $word_list (@word_list) {
print OUTFILE "$word_list \n";
}
close (OUTFILE);
I need to read text files from a directory and do some operations on all the files at once. This in order to get frequency counts for words over all files. Any guesses to why this code is not working?
The error message is: "Cannot open 'C:\Doc...\*.txt' Invalid argument at line 12"
While reading from each file, I would also like remove punctuation marks, s.a ". , ; : ? !" etc and write the output in the same file as I read from. Any ideas on how to do that?
Best,
lillyth.
#!/usr/local/bin/perl -w
use strict;
use lib 'C:\Documents and Settings\Usr1\Desktop\L';
use Lingua::EN::Tagger;
open (OUTFILE, '>>terms.txt'); # output file
@ARGV = 'C:\Documents and Settings\Usr1\Desktop\L\textFiles\*.txt';
my $tagged_text = '';
my $p = new Lingua::EN::Tagger;
while (<>) {
while(<$_>){
my $temp = $p->add_tags( $_ );
$tagged_text = $tagged_text. $temp ;
}
}
my @word_list = $p->get_words( $tagged_text );
foreach my $word_list (@word_list) {
print OUTFILE "$word_list \n";
}
close (OUTFILE);