http://www.perlmonks.org?node_id=1072583


in reply to Re: Execute function before exit of do() block
in thread Execute function before exit of do() block

I've been thinking about this, too, prior to writing my $SIG{__DIE__} answer above.
*sigh*
Creating a sentinel object... slowly, the objectification creeps on every subject...

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^3: Execute function before exit of do() block
by moritz (Cardinal) on Jan 29, 2014 at 21:04 UTC

    Well, in Perl 6 there are are non-object options, like a LEAVE block that is called on every scope exit, or an UNDO block for unsuccessful scope exists.

    I wonder if those are possible (and worthy) to backport to perl 5...

      Maybe that could be done in a cheap way overriding eval. Brrr... just as I am writing this, overriding eval feels very evil... ;-)

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^3: Execute function before exit of do() block
by ikegami (Patriarch) on Jan 30, 2014 at 00:22 UTC
    You could use clear or free magic if you wanted to avoid objects.