You have to compile the input.  Try using eval.

It should look something like:

while (<STDIN>) {
    $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, 2003 12:45 PM
> To: [EMAIL PROTECTED]
> Subject: scalar number or string?
> 
> 
> 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 (<STDIN>) {
>     $calc=$_;
>     print $calc."\n";
>     last;
> }
> if you run that last one and type 3+5-2, you get 
> 3+5-2.(string "3+5-2", not the number 6)
> Why is it so? And how can I get it to calculate the thing?
> I have gone through all of the perldoc perlfaqs. Maybe the 
> answer is so simple that I don't see it. I am just trying to 
> build a simple calculator. I have found a rather complicate 
> solution which works, but there must be a very simple 
> solution, isn't it?
> 
> Jacques L
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to