Re: Working with eval



On May 9, 12:25 am, "nobul...@xxxxxxxxx" <nobul...@xxxxxxxxx> wrote:
On May 8, 12:26 am, Mahurshi Akilla <mahur...@xxxxxxxxx> wrote:



On May 7, 4:17 pm, Mahurshi Akilla <mahur...@xxxxxxxxx> wrote:

Is there a way to check if eval works/fails so I can do the below ?

if ( ## eval can return successful ans )
{
$ans = eval($line);}

else
{
$ans = $line;

}

Thanks

Mahurshi Akilla

I am currently doing
if (eval($line)
{
// blah

}

and it seems to work fine.

However, I am seeing the below warning. However, those line numbers
are not giving me any clue on why this is happening:

Then give yourself some clues. For example print out the value of
$line before you eval it.

Unquoted string "o" may clash with future reserved word at (eval 9)
line 2, <STDIN> line 7.

Any comments?

It appears you did not use strict. Can you explain why? (Use strict
switches off 3 features of Perl that are only rarely useful and can
cause great pain if you accidently write code that makes perl think
that you wanted to use them).

If you had used strict you'd not get the above warning - you'd get an
error because unquoted strings are one of the 3 features it switches
off. I'm guessing you were not actually intending to use this feature.

It applears that $line actually contains more than one line. Did you
expect this?

You can change "(eval 9)" to something more helpful if you like - but
this only makes sense if there's something sensible you could use to
describe where the value in $line comes from.


what i was fundamentally trying to do there is this:

if $line contains an arithmetic expression that can be simplified to a
number, set $ans to that number.

if not, (in cases where there are variable names), go into a seperate
procedure and substitute the values for those variables until it is
simplified as much as possible, and re-run eval on it (hoping the
final answer would be a number). however, if the answer also contains
letters along with numbers, i want it to display whatever it is.

the problem is that as soon as it does eval($line), it shows a warning
on the screen if $line contains letters. instead of that warning, i
would like a pass/fail (0/1) value that i could use in my if
statements.

i hope i explained this clearly.

Mahurshi Akilla

.



Relevant Pages

  • Re: crossword project works
    ... black image and blank clue lists. ... Then I gave it a clue file by concatenating the times and biochemistry ... cluefile.c:54: warning: suggest parentheses around assignment used as ...
    (comp.programming)
  • Re: suggestion for an unambiguous hex notation
    ... Is this ANS Forth compatible? ... Win32Forth allows programmers to specify whether threaded code (but ... from TURNKEYed applications then the systems warns you that your word ... warning then you can ...
    (comp.lang.forth)
  • Re: Inverse of a Matrix
    ... Warning: Matrix is close to singular or badly scaled. ... Inf Inf ...
    (comp.soft-sys.matlab)
  • Re: Inverse of a Matrix
    ... Warning: Matrix is close to singular or badly scaled. ... Inf Inf ...
    (comp.soft-sys.matlab)
  • Re: new laptops around the corner
    ... It does appear that they're finally getting a clue about what features are actually useful. ... The "all day" battery and WUXGA are major steps in the ...
    (alt.sys.pc-clone.dell)