Using eval 
Author Message
 Using eval

after reading about the eval command I am still fuzzy on how it works.

 Am I right in thinking that it is basically the system command, but working
  from within the perl program?

Mike
--

One hour from now another species of life form will   |  Northern Telecom  
disappear off the face of the planet... FOREVER!      |  Rochester, NY
..AND THE RATE IS ACCELERATING!! -Megadeth :(



Mon, 01 Dec 1997 03:00:00 GMT  
 Using eval

Quote:

>after reading about the eval command I am still fuzzy on how it works.
> Am I right in thinking that it is basically the system command, but working
>  from within the perl program?

Hmm, sort of, I suppose.

It passes the string you give compiles it up and executes it there and
then. All your perl variables etc - including "local" and "my" variables
- are available, and can be modified.

It's just like the "eval" in the shells, if that helps.

It has a secondary use, since fatal errors in the eval don't cause the
outer interpreter to exit, so you can defatalise some errors (e.g.
"socket not implemented on this perl").

It's rarely needed, especially with all the fancy stuff in Perl 5.
I've found that in 80%+ cases where I'd use eval in perl 4, an anonymous
sub does the trick in perl 5 - this doesn't have to be recompiled all
the time, so is quicker.

Ian



Mon, 01 Dec 1997 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Test for eval() without using eval() ??

2. Using eval() for subroutine unwind

3. Using eval to iterate over a set of Perl variables

4. Using Eval Statement To Trap Module Not Present Fatal Error

5. using eval to create formats

6. Using eval in regex

7. Using eval and $@

8. how to setup exit routine using eval

9. using eval

10. dynamic object instantiation using eval

11. problem using eval with array of file test operators

12. Bug when using eval

 

 
Powered by phpBB® Forum Software