#! usr/bin/perl use warnings; open (TEXTFILE, 'text.txt') or die ("Cannot open file : $!"); $big_string = ; $big_string = lc ($big_string); $big_string =~ s/\(|\)/ /g; @words = split (/[,.\s+]/, $big_string); foreach (@words){ push @gt_three_char_words, $_ if /[a-zA-Z]{4,}|[a-zA-Z]{3,}'/; } foreach (@gt_three_char_words) { $hash{$_}++; } foreach $key (sort {$hash{$b} <=> $hash{$a}} keys %hash) { for ($i=0; $i<=9; $i++) { print "$key\t\t= $hash{$key}\n"; }} #### #! usr/bin/perl #midterm part 1 use warnings; use strict; my @gt_three_char_words = (); my %hash = (); open (TEXTFILE, 'text.txt') or die ("Cannot open file : $!"); my $big_string = ; $big_string = lc ($big_string); $big_string =~ tr/()//d; my @words = split (/[,.:;!?\s]+/, $big_string); foreach (@words) { push @gt_three_char_words, $_ if /[a-zA-Z]{4,}|[a-zA-Z]{3,}'/; } foreach (@gt_three_char_words) { $hash{$_}++; } foreach my $key ( (sort {$hash{$b} <=> $hash{$a} } keys %hash ) [0..9] ) { print "$key\t\t= $hash{$key}\n"; }