you apparently consider INIT blocks to be at best useless, at worst harmful, and certainly misnamed (i.e. not suitable for initialization). Do you have any use for them?

Useless: no. Harmful: no. Misnamed: no. Misunderstood: yes! They're useful when, and only when, you need to delay execution of something to before the program starts. For instance, Attribute::Handlers use INIT out of necessity, because it has no way of doing what it needs to do (for subroutines) at compile-time, so it needs to delay it to run-time (but even there it's not optimal to use INIT because it delays execution unnecessarily much, but it's the best Perl currently gives you). INIT should be used when you need to delay initialization code, not just execute initialization code in general.

Regarding p 223 in Camel 3rd: It doesn't say that BEGIN and INIT may be equivalently used. It says that you can use both. It doesn't mean that one of them in general isn't better or that they don't have different uses.

If INIT blocks are so evil, why is the Camel giving such advice?

I guess that's a question the authors answer best. Update: As should be clear in my very first four sentences in this post I don't consider INITs evil. The misuse of them is though. (Whether the Camel misuse them or not I don't know since I don't own the Camel.)

ihb

See perltoc if you don't know which perldoc to read!


In reply to Re^11: Making a variable in a sub retain its value between calls by ihb
in thread Making a variable in a sub retain its value between calls by crashtest

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.