Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7429151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:55:25+00:00 2026-05-29T08:55:25+00:00

When you use exec() in Perl: Note that exec will not call your END

  • 0

When you use exec() in Perl:

Note that exec will not call your END blocks, nor will it invoke DESTROY methods on your objects.

How do I force perl to call END blocks anyway? Can I do something like END(); exec($0) or whatever?

I really am trying to make the program end its current instance and start a brand new instance of itself, and am too lazy to do this correctly (using cron or putting the entire program in an infinite loop). However, my END subroutines cleanup temp files and other important things, so I need them to run between executions.

Unhelpful links to code:

https://github.com/barrycarter/bcapps/blob/master/bc-metar-db.pl

https://github.com/barrycarter/bcapps/blob/master/bc-voronoi-temperature.pl

https://github.com/barrycarter/bcapps/blob/master/bc-delaunay-temperature.pl

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:55:26+00:00Added an answer on May 29, 2026 at 8:55 am

    To answer the narrow question of how to invoke your END blocks at arbitrary times, you can use the B::end_av method with B::SV::object_2svref to get the code references to your END blocks.

    sub invoke_end_blocks_before_exec {
        use B;
        my @ENDS = B::end_av->ARRAY;
        foreach my $END (@ENDS) {
            $END->object_2svref->();
        }
    }
    
    END { print "END BLOCK 1\n" }
    END { print "END BLOCK 2\n" }
    
    ...
    
    invoke_end_blocks_before_exec();
    exec("echo leave this program and never come back");
    

    Output:

    END BLOCK 2
    END BLOCK 1
    leave this program and never come back
    

    I would usually prefer something less magical, though. Why not a structure like

    sub cleanup { ... }
    END { &cleanup }
    
    if (need_to_exec()) {
        cleanup();        # same thing END was going to do anyway
        exec( ... );
    }
    

    ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the next query that I run via SQLCMD.EXE use [AxDWH_Central_Reporting] GO EXEC
I need to convert a init.d script that uses ruby to not use ruby.
I was reading some questions about not to use exec or eval in python
I have a number of command line scripts in PHP that use exec() to
I am not able to use exec with mail command on found files. #
It looks like you can't use exec in a function that has a subfunction...
Is there any way to execute perl code without having to use Runtime.getRuntime.exec(...); (parse
If we don't use exec(ls -l) in PHP, but use readdir() or scandir() to
I would like to use Runtime.exec() to initiate another process in a directory with
I'm trying to use Runtime.exec to start a copy of the current process. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.