On Fri, Jul 23, 1999 at 02:54:02PM -0400, Michael G Schwern wrote: > On Fri, Jul 23, 1999 at 02:23:35PM -0400, Ronald J Kimball wrote: > > For shortest, can anyone beat this one-liner? > > > > perl -e'while(<>){$t+=1+ord($1)-ord"a"while/(.)/g;print if$t==100;$t=0}' > > I get Yugoslavia out of this, which ain't right. You forgot to normalize > your data. Just stick an lc in there like so: > > perl -e'while(<>){$t+=1+ord(lc$1)-ord"a"while/(.)/g;print if$t==100;$t=0}' > No, you forgot to normalize _your_ data. My data are already lowercase words. *grin* > Anyhow, here's the solution I came up with: > > perl -nle 'BEGIN{%c=map{($_=>++$c)}"a".."z"}$s=0;print if map({$s+=$c{lc$_}}split("")),$s==100;' <word file> > Nice way of using the other approach (which, it should be noted, is character-map independent, unlike the ord() approach.) It can be trimmed a bit, though... perl -nle 'BEGIN{%c=map{$_,++$c}a..z}$s=0; print if map({$s+=$c{lc$_}}split//),$s==100' <word file> But I should have used -n as well... perl -ne'$t+=1+ord($&)-ord"a"while/./g;print if$t==100;$t=0' with much thanks to Peter Scott for suggesting $& instead of $1. Ronald ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe