Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!munnari.oz.au!uniwa!DIALix!metapro!bernie From: bernie@metapro.DIALix.oz.au (Bernd Felsche) Newsgroups: comp.lang.perl Subject: Re: Perl and Cnews (was: While learning PERL... a suggestion) Message-ID: <1991Feb5.032342.25108@metapro.DIALix.oz.au> Date: 5 Feb 91 03:23:42 GMT References: <1991Jan23.230154.27272@dbsm.oz.au> <1991Jan24.174047.2897@NCoast.ORG> <1991Feb2.150543.569@haapi.uci.com> <1991Feb04.033031.2714@convex.com> Organization: MetaPro Systems, Perth, Western Australia Lines: 47 In <1991Feb04.033031.2714@convex.com> tchrist@convex.COM (Tom Christiansen) writes: >Look at /usr/local/lib/news/newsbin/expire/recovact for another good >candidate. Here's a loop in it: > while read group max min fourth > do > dir=`echo $group | tr . / ` # map ng name to directory name > new= > if test -d $NEWSARTS/$dir > then > new=`ls $NEWSARTS/$dir | egrep '^[0-9]+$' | sort -n | tail -1` > fi > case "$new" in > "") new=$max ;; # no files -- preserve old value > *) if test "$new" -lt "$max" # old value more recent (!) > then > new="$max" > fi > ;; > esac > dots="`echo $max | tr 0123456789 ..........`" > max="`expr 0000000000$new : '.*\('$dots'\)$'`" # preserve length > echo $group $max $min $fourth > done active.new >I'm quite certain that would run faster in perl. Sure it would. One fork-exec is a *lot* faster than seven (7) per newsgroup (I'm assuming lots of built-in shell bits). There are over 700 newsgroups on our machine. The use of "ls" to generate filenames is a trifle silly, especially as it's only being used to find the maximum article number. A simple perl routine could read the directory and simply look for a maximum. It doesn't even have to sort. (btw: if people didn't screw around with timestamps so badly, then new="`ls -tr [0-9]*|tail -1`" would have done the same trick.) I'm only now starting to play with Perl, but I can easily see why it's so popular for things like this. -- _--_|\ Bernd Felsche #include / \ Metapro Systems, 328 Albany Highway, Victoria Park, Western Australia \_.--._/ Fax: +61 9 472 3337 Phone: +61 9 362 9355 TZ=WST-8 v E-Mail: bernie@metapro.DIALix.oz.au | bernie@DIALix.oz.au