http://www.perlmonks.org?node_id=994031


in reply to Re^4: hash to count words
in thread hash to count words

Now that I have that under control, how do I print the output of the script to a file? I cannot figure it out. Thanks in advance and of course here is my coding.
#!/usr/bin/perl -w foreach $file (@ARGV) { open (IN, $file) or die "Cannot open file '$file' : $!\n"; while(<>) { $line = <IN>; @array = split (' ', $line); foreach $word (@array){ $word =~ s/[^\w\s]//g; $word = lc ($word); $wordcount{$word} += 1; } } foreach $key (keys %wordcount) { print "Word: $key " . ($wordcount{$key}) . "\n"; } } print ("scriptOutput\n\n");