kpc00@JUTS.ccc.amdahl.com (kpc) (10/27/90)
OK, I've got perl now. 1. How good is pl36 a2p supposed to be, in general? I've got a 5-page nawk program that doesn't compile right, and when it is transformed into simpler expressions (I had some nested assignments, getlines, and increment operations in a blockless loop), it wouldn't run. I added commas to some print statements to make it run, but it didn't run correctly. Oh, well. I'm just wondering how much effort I'd be likely to have to put into it to get it to run in perl (the point of doing which is mainly to evaluate perl, since the nawk script works quite well running in nawk in most cases). 2. Since I can't quite use the above-mentioned nawk program for comparative cyberlinguistics (:-)), I would really find it very helpful to see how a very simple shell script is best converted into perl. (O.K., "There Is M.T.O.W. To Do It": I would be happy to see several, or even many, versions.) How would the following simple safe-copy script be converted elegantly or efficiently, preserving its semantics? (Ideally, the file would contain both a perl and an sh script, and would execute the sh script on any machine where perl is not available. Would this use the END literal somehow?) ========== : # #kcp # #non destructive cp and mv and ln. # #use getopts trashdir=${TRASHDIR:?`no trashdir`} #using CMD=/bin/`basename $0` instead is possible, but undesirable if [ "$1" = '-R' ] #rm then /bin/mv $* $trashdir exit 0 elif [ "$1" = '-m' ] #mv then CMD=/bin/mv shift elif [ "$1" = '-l' ] #ln then CMD=/bin/ln shift else #cp CMD=/bin/cp fi if [ $# -lt 2 ] then echo usage: cp file1 file2 or cp file+ dir 1>&2 echo usage: -m moves; -l hard-links. \(too few args\) 1>&2 exit 1 fi #set -A and $# in ksh #just ${`eval $#`} for i do lastarg=$i done if [ ! -d $lastarg ] then if [ $# -ne 2 ] then echo usage: cp file1 file2 or cp file+ dir 1>&2 echo usage: -m moves; -l hard-links. \(too many args\) 1>&2 exit 1 fi if [ -f $2 -a -f $1 ] then #copy preserves permissions of target #we want ctime changed, mtime preserved, and atime preserved #possibly use mv and chmod, being careful with linked files #possibly use cp and a touch equivalent. echo kcp: copying $2 to trash first. 1>&2 /bin/cp $2 $trashdir fi $CMD $1 $2 else for eachfile do if [ $eachfile != $lastarg ] then file=$lastarg/`basename $eachfile` if [ -f $file -a -f $eachfile ] then echo kcp: copying $file to trash first. 1>&2 /bin/cp $file $trashdir fi $CMD $eachfile $file fi done fi ========== 3. Is perl one of the fastest interpreters around? That, along with its system call interface, seems to be its strongest point. How does it compare to various Schemes, I wonder? (And are there any good Lisps that can do pattern matching as well as perl does?) -- If you do not receive a reply from me, please resend your mail; occasionally this site's mail gets delayed. Neither representing any company nor, necessarily, myself.