in reply to Mini-rant about 'strict'

As several noted, BEGIN helps here. To further discourage such mistakes, I never write a scipt like you wrote. I write something more like:

use warnings; use strict; Main( @ARGV ); exit( 0 ); my %hash; BEGIN { %hash = ( bar => 'value' ); } sub Foo { print $hash{shift(@_)} } sub Main { Foo('bar'); }

so that any code outside of subroutines but below the call to Main() never gets run (rather than being run when it might be too late).

Even more than my %hash = BEGIN { ... };, I'd like:

sub Foo { my %hash = ( bar => 'value' ) BEGIN; print $hash{shift(@_)}; }

That is, have BEGIN be available as a block-less statement modifier like 'if', 'for', and 'while'; which gives us "static" variables.

- tye