#!/usr/bin/perl $HOME = $ENV{HOME} || $ENV{LOGDIR} || (getpwuid($<))[7] || '/'; $CAP = "$HOME/etc/caps"; # if ($] >= 5) { require 'AnyDBM_File.pm'; } dbmopen(CAP, $CAP, undef) && $dbm++; while () { chop; # allow and blank lines comments in data file s/#.*//; next if /^\s*$/; # one or two tab-separated fields ($lhs, $rhs) = split(/\t+/); # if no rhs, is capitalized lhs ($rhs = $lhs) =~ s/(\w+)/\u$1/g unless $rhs; # be kind to typos $lhs =~ s/^\s+//g; $rhs =~ s/^\s+//g; $lhs =~ s/\s+$//g; $rhs =~ s/\s+$//g; warn "dup: $lhs $rhs $CAP{$lhs}\n" if defined($CAP{$lhs}) && $debug; # save in parallel arrays for later sorting push(@lhs, $lhs); push(@rhs, $rhs); } # this sorting puts "tom christiansen" before "tom" for $i ( sort {index($lhs[$b],$lhs[$a]) >= 0} 0..$#lhs) { # preserve the lhs's whitespace $lhs[$i] =~ s/\s+/(\\s+)/g; $reg = 0; $rhs[$i] =~ s/\s+/'$' . ++$reg/ge; # save code for later eval; lhs's at word boundaries only $code .= "s/\\b$lhs[$i]\\b/$rhs[$i]/g;\n" } print "CODE: $code\n" if $debug; # read all input into pattern space $/ = undef; # $_ = <>; while (<>) { tr/A-Z/a-z/ if $squish; # find initial letters in sentences, which may have smileys s/([.!?](\s*:-\))?)(\n\s*|\s{2,})([a-z])/$1$3\u$4/g; # process special case words eval $code; die $@ if $@; # in case we missed the first word s/^(\s*[a-z])/\U$1/; s/(\w+)/$CAP{$1} ? $CAP{$1} : $1/ge; print; } __END__ colorado springs Colorado Springs convex computer corporation CONVEX Computer Corporation i unix UNIX tom christiansen Tom Christiansen larry wall Larry Wall limon dfw DFW grand junction long beach san diego cos COS co CO ca CA tx TX snmp SNMP cmu CMU mit MIT rpc RPC www WWW jeff polk kolstad new york kelm new jersey faq FAQ robbie santa clause cfv CFV star trek pc PC mark hess bsdi BSDI bsd BSD sysv SysV ibm IBM united states brownsville hill country afb AFB hondo del rio san antonio rio grande brownsville cotulla harlingen mcallen McAllen port isabel south padre corpus christi kingsville port aransas ellington houston hobby palacios port arthur dfw airport dallas love navy dallas fort worth greenville longview lufkin abilene mineral wells wichita falls stephenville midland san angelo el paso dalhart childress new year's day new year's eve jeffy christmas day christmas eve rob alladin drew fred