in reply to END blocks created at run time?

{ my @toDelete; END { for( @toDelete ) { unlink $_ or warn "Can't delete $_: $!\n"; } } sub new_tmpfile_name { # ... push @toDelete, $name; return $name; } }

This handles both dieing before any files have been create and dieing after more than one file has been created. Just another way to do it.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Many actions at END
by merlyn (Sage) on May 08, 2001 at 18:20 UTC
    You can generalize this:
    BEGIN { my @coderef; END { $_->() for @coderef } sub atEND { push @coderef, @_ } } ... sub new_tempfile_name { ... atEND(sub { unlink $name }); return $name; }
    Now you can add other things dynamically as well, using one mechanism, just by passing a coderef (usually a closure).

    -- Randal L. Schwartz, Perl hacker