#!/usr/bin/perl
sub count_words_in_line {
# use our to declare global variable.
our %word_count;
# below two lines can be combined into one like this - @words = split " ", shift
$line = shift @_;
@words = split " ", $line;
foreach my $word (@words) {
$word_count{$word}++;
}
}
sub count_words_in_file {
my $file = shift;
print $file . "\n";
open (FILE, $file) || die "$0: @_: $!";
while (my $line = ) {
count_words_in_line $line;
}
}
#print @ARGV[0] . "\n";
$file_name = shift;
count_words_in_file $file_name;
print %word_count;