|Pathologically Eclectic Rubbish Lister|
"state variables" are a new feature in Perl 5.10 that "are similar to my variables, but are declared with the state keyword in place of my. They're visible only in their lexical scope, but their value is persistent: unlike my variables, they're not undefined at scope entry, but retain their previous value."
So, as I understand this, this new kind of variables is like "static" variables in C and allow you to write code like:
Before Perl 5.10 you can do that with:
This way allows you to share a common $count variable between more than one sub:
Since I find the latter very simple to follow and understand I would like to know if there are differences between them and when one or the other should be used
Thanks in advance!citromatik