[philiptellis] /bb|[^b]{2}/
Never stop Grokking

Friday, July 24, 2009

Avoid running END blocks in perl

To run perl code without executing any END blocks, put this at the end of your program:
You'd put that in place of any exit() statement as well. I'll leave it to you to figure out return values. It's not that hard.

So, why did I need this?

I have this large program in perl, and it has a module that prints out a bunch of stats in the END block. This is all fine for the default use case, but today I needed to write another small program that does a bunch of auditing on this module - something like a unit test, but not exactly.

Anyway, this smaller program only needed the module to initialise, but not actually execute, and it doesn't require the stats at the end of the code to be printed either, so I needed to figure out how to run a program without executing the END block.

I looked up the perlmod doc, and it said that the only conditions under which END is not executed is if the process is replaced using exec or you're thrown out of the water by a signal. VoilĂ , no more END.


March 20, 2010 2:24 PM

You can use POSIX:_exit($status) instead.

Post a Comment