#!/usr/bin/perl -w #use strict; my $infile = $ARGV[0]; my $act = $ARGV[1]; my $included = "n"; my $lvar =""; my %validchars; if ($#ARGV < 1) { print "Usage: $0 Where can be -a, -c, or -r: -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; } if ( $act eq '-a' ) { %validchars = map { $_ => uc $_ } ( \x00 .. \xff ); } elsif ( $act eq '-c' ) { %validchars = map { $_ => $_ } ( 'A' .. 'Z', 'a'..'z' ); }; 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) { if (exists $validchars{$_}) { my $target = $validchars{$_}; $count++; $histogram{$target}++}; }; print "Of $count charactors:\n\n"; for (sort keys %histogram) { if ($_ eq "\n") { print "'\\n' occurred $histogram{$_} times. (".(($histogram{$_}/$count)*100)."%)\n"} else { print "'$_' occurred $histogram{$_} times. (".(($histogram{$_}/$count)*100)."%)\n" } };