[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] arithmetic within a string?



On Thu, 29 Jun 2000 19:18:42 -0700, Paul N. Schatz wrote:

>$do = 3.4*5.6;
>print "3.4*5.6 = $do\n"; # gives 3.4*5.6 = 19.04
>****************
>
>	Am I correct that there is no way to have the arithmetic occur
>within the string?

There are at least 3 ways.

1:	print "3.4*5.6 = @{[ 3.4*5.6 ]}\n";

2:	print "3.4*5.6 = ${\(3.4*5.6)}\n";

3: using MJD's "Interpolation" module (see CPAN):

	use Interpolation 'eval' => 'eval';
	print "3.4*5.6 = $eval{3.4*5.6}\n";


It works by creating a tied hash, %eval, linked to the built-in function
(in the module) 'eval'. The trick is that the hash key is executed as
code before being passed to the tied hash. The function 'eval' simply
passes that key along.

-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org