Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: idea for an static variable

by duff (Parson)
on Jul 14, 2006 at 04:29 UTC ( [id://561138]=note: print w/replies, xml ) Need Help??


in reply to idea for an static variable

Perl6 has a similar thing to C-style static vars. Except they're declared with the state declarator. In the following code the variable $x will maintain its value across successive invocations of the subroutine and is only visible within the subroutine:

sub foo { state $x = 1; say $x++; } foo; # outputs 1 foo; # 2 foo; # 3

Perl6 is full of all sorts of interesting declarators. See http://dev.perl.org/perl6/doc/design/syn/S03.html#Declarators

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://561138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-24 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found