in reply to Re: die through several evals
in thread die through several evals

i have sub $s and i execute something like
eval { $s->(); };
on alarm i die and if there any non-propagating evals in $s i'll stuck =(

Replies are listed 'Best First'.
Re^3: die through several evals
by BrowserUk (Patriarch) on Apr 24, 2013 at 15:31 UTC
    ... i'll stuck

    Stuck where? Doing what?

    I don't see anything getting "stuck"?:

    sub mys{ print "??$_[0]??"; eval{ die 'bad stuff' if $_[0] eq 'die' }; };; print 'here'; eval{ mys( 'hello' ) }; print 'there'; eval{ mys( 'die' ) }; print 'over here';; here ??hello?? there ??die?? over here

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      $SIG{ALRM} = sub { die "TIMEDOUT" }; my $sub = sub { warn "visible"; eval { # some big action in eval sleep(); }; warn "invisible"; }; # execute $sub with timeout alarm(1); $sub->();
      and get
      visible at -e line 1. invisible at -e line 1.

        That is exactly what is meant to happen.

        You wrap code in an eval in order to trap any error that might occur. If you then chose to not check for an error having occurred, then the code will continue as if no error had occurred.

        If you don't want the error to be ignored, you should either check for an error and rethrow if that is apppropriate; or don't use the eval in the first place.

        (And your 'visible'/'invisible' strings make no sense because: a) they are both visible; b) they should be!)

        I think that you'd better describe the overall goal you are trying to achieve, rather than looking to find a way to undo the very effect that the eval statement is designed to provide.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.