iwanthome has asked for the wisdom of the Perl Monks concerning the following question:
My test code is like this:
#!/usr/bin/perl $code = 'if($a>$b){'; $code .= '$result = 1;}'; $a =1; $b = 0; $result =0; eval $code; print $@ if ($@); print $result;
| There are no information displayed on the screen. What's wrong with the code ? |
| thanks! |
Update
To bmann:
yes,it is right.But I have another question:
#!/usr/bin/perl $code = 'if($port_a $cmp_op $port_b){$result=1;}'; $code .= 'else{$result=0;}'; $port_a =7777; $port_b = 6666; $cmp_op = ">"; eval $code; print $@ if($@); print $result; $perl eval Scalar found where operator expected at (eval 1) line 1, near "$port_a + $cmp_op" (Missing operator before $cmp_op?)
So I can't use eval like that which I must specify operator not scalar,is it true ? Are there any solution to do this ? thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to use eval?
by matija (Priest) on Apr 09, 2004 at 07:30 UTC | |
by iwanthome (Beadle) on Apr 09, 2004 at 07:37 UTC | |
by bmann (Priest) on Apr 09, 2004 at 07:51 UTC | |
by matija (Priest) on Apr 09, 2004 at 08:09 UTC | |
by ambrus (Abbot) on Apr 09, 2004 at 20:55 UTC | |
|
Re: How to use eval?
by BUU (Prior) on Apr 09, 2004 at 10:26 UTC | |
by xenchu (Friar) on Apr 09, 2004 at 18:34 UTC | |
by bmann (Priest) on Apr 09, 2004 at 19:19 UTC | |
|
Re: How to use eval?
by Anonymous Monk on Apr 10, 2004 at 03:42 UTC |