I see this type of code too often:
Or things like that:
If you are using a non-ancient version of Perl (that is, 5.10 or more), you should consider using the
state keyword. It’s similar to the static variables inherited from C.
From the documentation :
state declares a lexically scoped variable, just like
my does. However, those
> variables will never be reinitialized, contrary to lexical variables that are
> reinitialized each time their enclosing block is entered.
So the two code snippets become :
Nothing terribly amazing here, but it’s really easy, saves keystrokes and makes the code more readable. So why not use it more widely ?