in reply to How to use eval?

There is nothing wrong with the code.

When I try it, it prints "1" to the screen, just as it should.

Now, if you had said print "$result\n"; at the end, that 1 would be on a line of it's own, and more easily visible - which is what I think your problem was.

Replies are listed 'Best First'.
Re: Re: How to use eval?
by iwanthome (Beadle) on Apr 09, 2004 at 07:37 UTC
    $ more eval #!/usr/bin/perl $code = 'if($a>$b){ $result =1} '; $a =1; $b = 0; $result =0; eval $code; print "eval error\n" if($@); print $result; $ eval $ perl -v This is perl, v5.8.2 built for sun4-solaris Copyright 1987-2003, Larry Wall
    You can see what's happened on my computer,there are nothing .
    Which perl version do you use ?Maybe it is a bug?
    thanks!
      eval is a shell builtin. Just rename your script or run it with perl eval.
        ./eval would probably work, too (or would at least complain if he forgot to make it executable...)