in reply to Re: Puzzled about strict
in thread Puzzled about strict
If this is not some kind of dispatch table for incoming commands, as is usually the case, but merely trying to save some keystrokes for setup code, I submit it is still the better approach. In that case, you'd accompany the construct with something likemy %table = ( foo => sub { ... }, bar => sub { ... }, baz => sub { ... }, # ... }
Because this way, changing the name of a function only need be done Once And Only Once. When you change the keyname, most dependent code automatically continues working. The softref approach to saving keystrokes means you have to maintain the function names both at the sub definition as well as at the setup loop (and possibly several other locations). (You can solve this by adding a layer of indirection. Think about that approach for 10 seconds though and you'll find you're exactly back to square one. Because you'd need to store the coderefs in a hash..){ my ($n, $r); no strict qw(refs); *{$n} = $r while ($n, $r) = each %table; }
Makeshifts last the longest.
|
|---|