stevieb has asked for the wisdom of the Perl Monks concerning the following question:

Instead of requesting help with writing code, I'm looking for feedback on my understanding of code.

I've written a short usage-case document for BEGIN and END, and am wondering if there are people who care to review it so that my understanding can be confirmed or corrected prior to sharing it in a better location.

The doc is in my scratchpad a more stable place.

If this is not the place to request such feedback, I apologize, and I'll know for next time :)

Steve
  • Comment on Feedback on my understanding of the five Named blocks

Replies are listed 'Best First'.
Re: Feedback on my understanding of the five Named blocks
by JavaFan (Canon) on Apr 03, 2012 at 20:52 UTC
    Here's a variation on one of your examples that show the difference between INIT and BEGIN:
    use 5.010; use strict; use warnings; persist(); INIT { my $store = init_store(); sub persist { say $store++; } } persist(); persist(); sub init_store { 0 } __END__ 0 1 2
    But if you change the INIT into a BEGIN, you get a run-time error:
    Undefined subroutine &main::init_store called at /tmp/xxx line 10. BEGIN failed--compilation aborted at /tmp/xxx line 14.

      This is a wonderful distinction between the two, thank you for the addition! I'll certainly factor this in :)

Re: Feedback on my understanding of the five Named blocks
by GrandFather (Saint) on Apr 03, 2012 at 21:03 UTC

    The Meditations section would probably be a better section for a "Request For Comment" (RFC). By convention such a node's title is prefixed "RFC:".

    Don't include links to material that may be transient. Put the material in your node instead. PerlMonks nodes are a resource that are referred back to for years. It's a real pain if the key information in the node has vanished because it was linked and the link has broken or the material has been altered.

    True laziness is hard work
Re: Feedback on my understanding of the five Named blocks
by Anonymous Monk on Apr 03, 2012 at 21:26 UTC