in reply to Re: multi thread problem in an simple HTTP server
in thread multi thread problem in an simple HTTP server

A small niggle. I guess that for compatibility reasons, there are special names for subroutines that make them get called implicitly:

> perl -le "sub BEGIN { print shift }; sub END { print shift }" Hello +World

outputs

Hello World

I've used this trick when writing a module for a version of Perl that didn't understand CHECK or INIT blocks (5.04_03 or something like that). I declared these blocks as subroutines and then had another subroutine to execute them if the Perl version was too low.

Replies are listed 'Best First'.
Re^3: multi thread problem in an simple HTTP server
by BrowserUk (Patriarch) on Apr 09, 2009 at 12:12 UTC

    Just goes to show that there is always something new to learn, I've never knowingly encountered this form before, but there it is documented. Albiet that it seems to be a non-feature as they are still not callable in the normal way. But, I sit corrected :)

    Five specially named code blocks are executed at the beginning and at the end of a running Perl program. These are the BEGIN, UNITCHECK, CHECK, INIT, and END blocks.

    These code blocks can be prefixed with sub to give the appearance of a subroutine (although this is not considered good style). One should note that these code blocks don't really exist as named subroutines (despite their appearance).


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.