as is being recommended to me

What the OP quoted wasn't nearly that specific. Keep in mind the goal of an idiom or practice when applying it. In this case, it's for "the readers of the code can immediately see that the lack of definition is intentional". That means that

my $var; BEGIN { $var = ...; }

satisfies the requirements. You can even put those two statements on the same line. I provided an example above of what would satisfy the practice if you had some complex initialization code in a previous post in this thread.

You always have to be very careful when using BEGIN blocks to make sure all the code that should be in a BEGIN block is in a BEGIN block. You've shown an example of this already when the inline module that did everything right was messed up by a BEGIN block in its user.

Basically, what I'm saying is you can't change

my $var = "some value"; ... code that uses $var ...
to
my $var = "some value"; BEGIN { ... code that uses $var ... }
You need to change it to
my $var; BEGIN { $var = "some value"; ... code that uses $var ... }

If you're particularly "picky", you could use

my $var; BEGIN { $var = "some value"; } BEGIN { ... code that uses for $var ... }

It has nothing to do with whether "some value" is there because PBP recommended it, or because it needs to be there for the code to function. I don't agree with the practice the OP quoted, but badly applying BEGIN blocks is not an argument against the practice.


In reply to Re^6: Use of uninitialized variables? by ikegami
in thread Use of uninitialized variables? by Zadeh

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.