(e-mail address removed) wrote in (e-mail address removed):
Assuming I have something like this:
I would to have to first ask why you are using a string eval for what is
just an anonymous sub invocation. You might have a good reason, but most
posters don't, so I ask.
Now, given that you are calling foo by name after the eval, I really
cannot think of any reason to use a string eval rather than an anonymous
subroutine.
my $str = "sub foo { print 1 / 0; }";
eval($str);
foo();
Compare it to
my $sub = sub { print 1/0 };
$sub->();
... then I get:
Illegal division by zero at (eval 1) line 1.
Can I somehow give the eval block a more meaningful filename than
"(eval N)"?
I don't know. Frankly, I don't think you should waste time on this.
If you use an anonymous sub you will get both compile time error
checking and the ability to apply hack #57 in the excellent "Perl
Hacks" book.
The code is available at <URL:
http://examples.oreilly.com/perlhks/>.
Download the archive at that location and look in
perl_hacks_examples\debugging\name_your_anonymous_subroutines
Sinan
--
A. Sinan Unur <
[email protected]>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/