in reply to Re: Perl Style: Is initializing variables considered taboo?
in thread Perl Style: Is initializing variables considered taboo?
my $x; initialises. Any trailing = is just a normal assignment that occurs after the variable has already been created and initialised.
The only situation I can think of is if you do
my $x; sub foo { ...[ use $x ]... }
If you use that as a Registry script, you'll have problems. Perl tells you about it with "will not stay shared" warnings. The fix is NOT to ignore the warning. You could fix it by switching to a package variables.
our $x = undef; sub foo { ...[ use $x ]... }
Unlike my, our doesn't initialise, so you have to initialise yourself.
* — The implementation varies a little, but you shouldn't notice any difference unless you do something disallowed like my $x if $cond;
|
|---|