#!/usr/bin/perl -w use strict; my $infile = $ARGV[0]; my $act = $ARGV[1]; my $included = "n"; my $lvar =""; my @validchars = ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); if ($#ARGV < 1) { print "Usage: $0 Where can be -a or -c: -a: show all charactors. (ie, spaces, etc.) -c: show only regular charactors, but keep case. (ie, x is different than X.) -r: show only regular charactors, disregard case. (ie, t and T are the same.)\n"; exit; } my $count = 0; system("cls"); #win system("clear"); #*nix open INPUT, "<$infile" or die "Couldn't open '$infile' : $!"; my $input = do { local $/; }; my %histogram; for my $char (split //, $input) { $included = "n"; if ($act eq "-a") { $histogram{$char}++; $count++; } elsif ($act eq "-c") { foreach $lvar (@validchars){ if ($lvar eq uc($char)) {$included = "y";} } if ($included eq "y") { $histogram{$char}++; $count++; } } elsif ($act eq "-r") { foreach $lvar (@validchars){ if ($lvar eq uc($char)) {$included = "y";} } if ($included eq "y") { $histogram{uc($char)}++; $count++; } } else { print "Bad charactor option: '$act'.\n"; exit; } }; print "Of $count charactors:\n\n"; for (keys %histogram) { if ($_ eq "\n") { print "'\\n' occurred $histogram{$_} times. (".(($histogram{$_}/$count)*100)."%)\n"} else { print "'$_' occurred $histogram{$_} times. (".(($histogram{$_}/$count)*100)."%)\n" } };