[comp.lang.perl] handy dandy cpp substitute using m4 & perl

dave@aspect.UUCP (Dave Corcoran) (02/15/91)

printf("Hello world\n");

Here is a short m4 macro which may present some interesting possiblities:


--------------------------8<-------------------------
#definitions here  
define(`pe_',
	`syscmd(perl -e ' '`
	$@
	''`
)')

dumpdef(`pe_')
define(cs_,`pe_(printf ("%2.2f,%2.2f",sin(cos($1)),cos($2));)')
define(x,`pe_(print cos($1);)')

#end definitions & begin invocations

double x [] = {pe_(
	for $i (1..20) {
		$i=sqrt($i);
		$j=sqrt($i+20);
		$out=join(",",$out,$i,$j,log($i));
	}
	($out=~s/,//); # note the parens are need to overide the ,
			# the m4 argument separator 
	print $out;
	)};


double y [] = {cs_(1,4),x(22)};
--------------------------------------8<--------------------------
-- 
David Corcoran		      -@@
uunet!aspect!dave	        ~
In a society where anything goes eventually everything will.