in reply to Overloading '{}' or 'sub'
See Scope::Guard, which is designed to do exactly that, you create it with a subroutine to run when it goes out of scope...
use strict; use warnings; use Scope::Guard; sub foo { my $blah = shift; my $sg = Scope::Guard->new( sub { print "This runs at the end of the scope\n"; } ); print "Doing some other stuff now...\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Overloading '{}' or 'sub'
by wdef2 (Acolyte) on Jan 01, 2009 at 22:52 UTC |
In Section
Seekers of Perl Wisdom