Aye. I once made a simple program, just for calculating + and *. I had no
problem with that. Which means somethin' like:
#!usr/bin/perl
print "Enter a number.";
$number = ;
# *ing by 2 (can't get to the right word)
$result = $number * 2;
print "Aye, the result is" . $result;
Which you could do
On Sun, Jan 19, 2003 at 06:44:31PM +0100, Jacques Lederer wrote:
> Hello,
>
> When you write
>
> $calc=3+5-2;
> print $calc."\n";
>
> you get 6. (number, not the string "3+5-2")
>
> When you write
>
> while () {
> $calc=$_;
> print $calc."\n";
> last;
> }
>
> if you run that last one a
From: Paul Johnson <[EMAIL PROTECTED]>
> On Sun, Jan 19, 2003 at 06:44:31PM +0100, Jacques Lederer wrote:
> > When you write
> >
> > $calc=3+5-2;
> > print $calc."\n";
> >
> > you get 6. (number, not the string "3+5-2")
> >
> > When you write
> >
> > while () {
> > $calc=$_;
> > print $calc
You have to compile the input. Try using eval.
It should look something like:
while () {
$calc= eval $_;
print $calc."\n";
last;
}
But, don't forget to catch errors.
Sasha
> -Original Message-
> From: Jacques Lederer [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, January 19, 2
"...if you run that last one and type 3+5-2, you get 3+5-2.(string "3+5-2", not the
number 6)" --Jacques
Hi Jacques,
Well, this is about data types. Unfortunately, Perl tends to haze up the issue by
doing away with explicit types and doing everything implicitly. In a programming, as
opposed
And how can I get it to calculate the thing?
print eval($calc) ."\n";
Hi Jacques,
Sorry. In my previous post, I answered your first question, but offered no solution.
Joseph
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]