#!/usr/bin/perl # word counting program use strict; use warnings; use autodie; # list of excluded words my %excluded = map { $_ => 1 } qw( a about although also an and another are as at be been before between but by can do during for from has how however in into is it many may more most etc ); ## list of excluded characters #my @excluded_chars = ( "\\'", "\\:", "\\@", "\\-", "\\~", "\\,", "\\.", "\\(", # "\\)", "\\?", "\\*", "\\%", "\\/", "\\[", "\\]", "\\=", '"' # ); # Read in whole file (uncomment next line) # local $/; my %count; # this will contain many words while (<>) { # remove punctuation tr{':@\-~,.()*%/[]="}{}d; foreach ( split ) { # remove excluded words next if exists $excluded{ lc() }; ++$count{ lc() }; # count each separate word } } foreach my $word (sort { $count{ $a } <=> $count{ $b } || $a cmp $b } keys %count) { print "$count{$word} $word\n"; }