How to keep a counter for removed duplicates inside a hash value?
chdir("c:/perl/normalized"); $docid=0; use List::MoreUtils qw( uniq ); my %hash = (); @files = <*>; foreach $file (@files) { $docid++; open (input, $file); while (<input>) { open (output,'>>c:/perl/postinglist/total'); chomp; (@words) = split(" "); foreach $word (@words) { push @{ $hash{$word} }, $docid; } } } foreach $key (sort keys %hash) { $size = scalar (@{$hash{$key}}); print output "Term: $key, Frequency:$size, Document(s):", join(" ", uniq @{ $hash{$key} }), "\n"; } close (input); close (output); before the join(" ", uniq @{ $hash{$key} }), the output was as follows: Term:of Frequency:3
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.