Stupid state trick
Occasionally I find myself writing a Perl subroutine that uses a module that no other part of the code needs. This subroutine may be called multiple times, or not at all. At some point I wondered if putting some logic around the require
statement would be faster than just calling it every time. require()
is idempotent, after all. You could do something like $counter++ or require Foo;
, but the variable has to live somewhere outside the subroutine. Not neat.
It occurred to me that, given P…