in reply to capturing $@ from an eval'd require

Drop eval STRING; use eval BLOCK:
eval { my $file = 'foo.pl'; require $file; };
As broquaint points out, $file will be interpolated into the string before the eval runs. To see what you're really doing, try this:
my $notwhatiwant = qq{ $file = 'foo.pl'; # foo has errors in it require "$file"; }; print "<$notwhatiwant>\n"; eval $notwhatiwant; dienice("that code is busted because: $@") if $@;
I think you'll be surprised.

Replies are listed 'Best First'.
Re: Re: capturing $@ from an eval'd require
by blahblah (Friar) on Jun 01, 2002 at 07:12 UTC
    Thanks a lot guys! The code is working great and I have a much clearer understanding of qq{}. This is the second time chromatic has contributed to solving a tricky bit for me this week - awesome.
    Thanks, alex