Path: utzoo!attcan!telly!lethe!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!convex!news From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: wc clone Message-ID: <1990Dec20.003805.8017@convex.com> Date: 20 Dec 90 00:38:05 GMT Sender: news@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 21 Nntp-Posting-Host: pixel.convex.com After reading a comment from Barry Shein on his having written a complete wc program in just 6 lines of Snobol in alt.religion.computers, I set out to do so in perl. Well, I'm down to 7 of perl, but without using comma-kludges, I can't quite trim off one more line. I've only thought about it for 5 minutes or so, I do admit. Maybe I'm missing something obvious. #!/usr/bin/perl -n $tchars += $chars += length; $twords += $words += s/(\S+)/$&/g; next unless eof; printf "%8d %8d %8d %s\n", $., $words, $chars, ($ARGV eq '-'?'':$ARGV); $tlines += ($.+0) + ($. = !reset wc); next unless $files++ && eof(); printf "%8d %8d %8d %s\n", $tlines, $twords, $tchars, "total"; --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