Static variables are the final type of variable available; these variables keep their value between calls to a function. About their effects, we will take a look at them through the following examples.
1 2 3 4 5 6 7 8 9 10 |
|
We all know it will print out 1, 2, till 10.
If we change it a little bit, like thhis:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
This program will print out 1, all 1.
What if we want to print out the “i” incrementally, we will use the static keyword.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
This example is excerpted from the book “extending and embedding perl”.