in reply to Re: Why eval {...};if ($@) { die $@ } else { ...???
in thread Why <c>eval {...};if ($@) { die $@ } else { ...</c> ???

Well.. Actually I don't think you have to play tricks with $SIG{__DIE__} to obtain a different result. calling confess() within the something(...) would show that additional frame as well.

I don't see any reason to want that though. What's that additional frame good for? Apart from maybe causing you to look at that part of the code and thus wasting time. I think the additional frame is at best confusing.

Replies are listed 'Best First'.
Re^3: Why eval {...};if ($@) { die $@ } else { ...???
by shmem (Chancellor) on Apr 03, 2009 at 23:19 UTC
    What's that additional frame good for?

    something() might be in some other module which you don't control. That technique allows you to delay the exit until the very line where you choose to die. An that's precisely what eval BLOCK is all about - delay the die, to mask it or die elsewhere.

      I probably do not understand what you are trying to say. I know what's an eval BLOCK good for. I do not know what's an eval BLOCK;if ($@) {die $@}; good for.

        Well. As you know, the eval BLOCK is good for not dying. The eval BLOCK; die $@ if $@ is good for dying somewhere else, and not inside the code that's in the eval BLOCK. I don't know the specifics of that module you are talking about, but I've provided a simple example which shows the difference, even not adding anything to the argument to die but $@.