Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

ReleaseAction

by tilly (Archbishop)
on Apr 16, 2001 at 22:00 UTC ( #72887=snippet: print w/replies, xml ) Need Help??
Description: Call an anon sub as it is destroyed. (Typically by going out of scope.) For instance:
use strict; use Cwd; use Carp; use ReleaseAction; sub cd_to { chdir($_[0]) or confess("Cannot chdir to '$_[0]': $!"); } sub temp_cd { my $cwd = cwd(); cd_to(shift); return ReleaseAction->new( sub {cd_to($cwd);} ); } # And a simple test system "pwd"; { my $var = temp_cd('/tmp'); system "pwd"; } system "pwd";
package ReleaseAction;

# Pass this a sub...
sub new {
  bless($_[1], $_[0]);
}

# and call it when it goes.
sub DESTROY {
  shift->();
}

1;
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://72887]
help
Chatterbox?
[MidLifeXis]: Project Admin, a while ago: "No, I would prefer you didn't close that ticket yet confirming $vendor's support process yet. Continue to periodically check back to see if it has changed."...
[MidLifeXis]: Project Admin, today, after many periodic updates from me: "Why hasn't this been closed yet? Is there anything I can do to get this closed?" <facepalm>

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2017-01-19 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.