in reply to What is the difference between eval and do?
Well, one difference is that do 'string' interprets 'string' as a file name, while eval 'string' interprets 'string' as Perl code:
$ perl -e 'do "print qq(foo\n)" or die qq($! $@)' No such file or directory at -e line 1. $ perl -e 'eval "print qq(foo\n)" or die qq($! $@)' foo
There are also other more subtle differences (such as do cannot see lexical variables in the enclosing scope, while eval can), but - believe it or not - it's all in the docs: do, eval :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What is the difference between eval and do?
by AGhoulDoingPerl (Sexton) on Feb 20, 2011 at 05:41 UTC |