Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!texsun!convex!news From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: wc clone Message-ID: <1990Dec20.020632.10077@convex.com> Date: 20 Dec 90 02:06:32 GMT References: <1990Dec20.003805.8017@convex.com> Sender: news@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 17 Nntp-Posting-Host: pixel.convex.com I save a LOT of time if I make the part that counts words throw out the string instead of save it: $twords += $words += s/\S+//g; I go from 1.7 seconds on /etc/termcap to 1.0 seconds. It's still a long ways from the C wc's 0.25 seconds, but not too shabby either. Anybody got a cleverer (and faster) algorithm? I sometimes wish I could just count the number of occurrences without having to make a new string. Not very often, though. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "With a kernel dive, all things are possible, but it sure makes it hard to look at yourself in the mirror the next morning." -me