Do you think if my following code is correct for implementing a static
method (maybe singleton, or class method) in perl class?
use strict;
use warnings;
package A;
sub new {
my $class = shift;
bless {},$class;
}
sub count {
our $int ||= 0;
$int ++;
return $int;
}
1;
package B;
print A->count,"\n";
print A->count,"\n";
print A->count,"\n";
The run results:
$ perl
t4.pl
1
2
3
I want a method like this one in scala code.
object Foo {
var int = 0
def increase = { int += 1; int }
}
println(Foo.increase)
println(Foo.increase)
println(Foo.increase)
Thank you.
--
Simple Mail
https://simplemail.co.in/