perlancar has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I just wasted half an hour trying to find a cause why a variable is undefined (and chasing the wrong rabbit of trying to figure out why a particular module won't load but require() doesn't raise an error), before finally realizing that I made a typo:
our $foo => { a=>'blah', b=>'blah', ... };
instead of:
our $foo = { a=>'blah', b=>'blah', ... };
And come to think of it, this is perhaps my third or fourth time being bitten by this. This mistake is not caught by warnings, so any suggestion on how to detect this? Perhaps there's a Perl::Critic policy somewhere and I need to just (re-)plunge and use Perl::Critic (again).
UPDATE 2017-01-23: my bad, it turns out I didn't use warnings in the original code. our $foo => value indeed produces warning in most cases.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Detecting 'our $foo => 1' mistake?
by haukex (Archbishop) on Jan 21, 2017 at 11:24 UTC | |
|
Re: Detecting 'our $foo => 1' mistake? (updated)
by haukex (Archbishop) on Jan 21, 2017 at 10:34 UTC | |
by LanX (Saint) on Jan 21, 2017 at 11:04 UTC | |
by haukex (Archbishop) on Jan 21, 2017 at 11:21 UTC | |
by LanX (Saint) on Jan 21, 2017 at 18:28 UTC | |
by ikegami (Patriarch) on Jan 23, 2017 at 17:14 UTC | |
|
Re: Detecting 'our $foo => 1' mistake?
by Anonymous Monk on Jan 21, 2017 at 10:17 UTC |