OK, I think I understand your question, but a little more code would have helped, as would specifying which Perl API -- not that it seems to matter to the answer, but it is a big part of your question. Having said that, the problem seems very simple.
When Perl hits an error, like most languages, it runs out through the calling contexts in order until it finds a place where it can handle the error. Perl's most basic error handling is eval{}
(but I'd use Try::Tiny
if you can, as it is then clearer that you're doing error handling instead of some of the other strange things eval can do).
Anyway, when Perl hits eval{}
, the whole of eval{}
exits, and $&
is set to the error. So, having the eval{}
outside the loop means errors will leave the loop. If you put the eval{}
inside the loop, when an error occurs, eval{}
will exit, but you will carry on to the next iteration. It's that simple.
I also detect signs that maybe you're not using use strict;
and use warnings;
. Please do, as they help you find many bugs quicker.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…