Move strict after all bog standard headers, but leave it before any complex logic. And, of course, where you need to, remove it. In this case 2 of 3 variables didn't need to be declared.package Example; use Exporter; @ISA = 'Exporter'; $VERSION = 1.02; use strict; use vars qw(@EXPORT_OK); my %METHODS = ( foo => 'bar', bo => 'baz', ); @EXPORT_OK = (keys %METHODS); foreach my $method (keys %METHODS) { no strict 'refs'; *$method = sub { return $METHODS{ $method }; }; } 1;
As for your objection about needing to use it, if you actually need to use it (as here) then of course it goes into a vars. But I find that 90% of the time the standard variables that you need for inheritance, Exporter, and versioning really shouldn't appear a second time. I see no need to spend effort making it possible unless I need to. And note the detail that if you have a typo on these standard variables, then warnings will catch it. So spelling isn't an issue.
As for the stupid mistakes that you refer to, we went through that before and there was not one you could find that I agreed on. Basically my attitude is that if you get in the habit of not playing unnecessarily cute games, then those mistakes don't happen. Plus your games wind up confusing other tools, like Carp. Trying to counteract one trick with another is something that I prefer to avoid.
In reply to Re (tilly) 4: Why doesn't @EXPORT = (keys %METHODS) work?
by tilly
in thread Why doesn't @EXPORT = (keys %METHODS) work?
by rrwo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |