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
tomy $var = "some value"; ... code that uses $var ...
You need to change it tomy $var = "some value"; BEGIN { ... code that uses $var ... }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |