Scope modifiers: Difference between revisions

Content deleted Content added
partial answer
Patrick (talk | contribs)
Line 305: Line 305:


Usually, <code>my</code> is preferrable to <code>local</code>, but one thing <code>local</code> can do that <code>my</code> can't is affect the special punctuation variables, like <code>$/</code> and <code>$"</code>. Actually, in perl 5.9.1 and later, <code>my $_</code> is specially allowed and works as you would expect.
Usually, <code>my</code> is preferrable to <code>local</code>, but one thing <code>local</code> can do that <code>my</code> can't is affect the special punctuation variables, like <code>$/</code> and <code>$"</code>. Actually, in perl 5.9.1 and later, <code>my $_</code> is specially allowed and works as you would expect.

In perl 5.10.0, a new Modifier <code>state</code> was intoduced. It can only be used with the 'feature' pragma, or an <code>use 5.01</code> (or greater).
A Variable introduced with <code>state</code> has no Dynamic scope, thus it doesn't change or vanish like one introduced with <code>my</code>.

<lang perl>
sub count_up{
state $foo;
$foo++;
}
</lang>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==