Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

ReleaseAction

by tilly (Archbishop)
on Apr 16, 2001 at 22:00 UTC ( [id://72887]=CUFP: print w/replies, xml ) Need Help??

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
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://72887]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2025-11-17 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.