Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!csd.unb.ca!morgan.ucs.mun.ca!nstn.ns.ca!news.cs.indiana.edu!att!linac!uwm.edu!wupost!uunet!email!swdsrv.edvz.univie.ac.at!nestroy!dec4.wu-wien.ac.at!neumann
From: neumann@dec4.wu-wien.ac.at
Subject: Re: Re: Which language can write this but Perl
Message-ID: <699765841;-}3527@dec4.wu-wien.ac.at>
Lines: 36
Sender: news@nestroy.wu-wien.ac.at (NetNews)
Nntp-Posting-Host: dec4.wu-wien.ac.at
Organization: WU-Wien
Date: Thu, 5 Mar 1992 03:24:01 GMT

In article <1097@smds.UUCP> from [3 Mar 92 07:53:45 GMT] you wrote:
  |> Is the perl solution correct?  That is, does it preserve the exact
 |> white space sequence between the number and the word?  Perl aficianados
 |> will tell us, I am sure.  

i do not think, it was not the intention of original perl program to preserve
the spacing. The program below accepts 0..n whitespace characters between
the number and the string "inch" and preserves it in the output. a whitespace 
character is either a blank, a tab, a newline, a carriage return or a form feed,

#!/usr/local/bin/perl -p
$*=1; $/=""; s|(\d+\.?\d*)(\s*)inch|sprintf("%0.2f$2cm",$1*2.54);|eg;

the eager reader might notice another subtle difference between this version 
and earlier versions: can anybody tell me, why people divided the inch figure
by 2.54 rather than multipying it? i know, it is just an example, and dividing was
part of the "specification", but...

a testfile:
1     inch
is less than 3.5
inches plus 7inches minus 8 inches...

the output:
2.54     cm
is less than 8.89
cmes plus 17.78cmes minus 20.32 cmes...

-gustaf

--
Gustaf Neumann          neumann@dec4.wu-wien.ac.at, neumann@awiwuw11.bitnet
Vienna University of Economics and Business Administration 
Augasse 2-6,  A-1090 Vienna, Austria		
Tel: +43 (222) 31-336 x4533  	Fax 347-555

