470,821 Members | 2,084 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,821 developers. It's quick & easy.

Does Perl have anything that equates to the C++ this pointer?

use AI::Genetic;
my $ga = new AI::Genetic( -fitness => sub { rand },
-type => 'bitvector',
-population => 500,
-crossover => 0.89,
-mutation => 0.01,
-terminate => sub {
$ga->getFittest->score() > 0.9 } );
$ga->init(10);
$ga->evolve('rouletteTwoPoint', 100);
print "Best score = ", $ga->getFittest->score(), "\n";

The above code is taken from the man page for AI::Genetic (with a bit
of cleanup and modification).

What I'm trying to do is replace "sub { rand }" with something more
meaningful. But to do that I need to be able to say something, in
C++, to the effect of "this.genes()". Any help that could be provided
would be greatly apreciated.
Jul 19 '05 #1
2 4063
Calvin wrote:
What I'm trying to do is replace "sub { rand }" with something more
meaningful. But to do that I need to be able to say something, in
C++, to the effect of "this.genes()". Any help that could be provided
would be greatly apreciated.


Your subject line is very confusing. I assume your use of 'this' in
the subject is not the same as the regular English definition of the word.

sub foo {
my $this = shift; # Pointer to self
my $arg = shift; # First argument given to method call
$this->genes($arg); # Call another method in the same class
}

-Joe

P.S. Next time, post to comp.lang.perl.misc instead of comp.lang.perl
Jul 19 '05 #2
Joe Smith <Jo*******@inwap.com> wrote in message news:<UuSOc.188251$a24.171398@attbi_s03>...

Your subject line is very confusing. I assume your use of 'this' in
the subject is not the same as the regular English definition of the word.

sub foo {
my $this = shift; # Pointer to self
my $arg = shift; # First argument given to method call
$this->genes($arg); # Call another method in the same class
}

-Joe

P.S. Next time, post to comp.lang.perl.misc instead of comp.lang.perl


Thanks for the help. As it turns out there was an undocumented
variable that's passed into the function in question that does the job
much more efficiently than the work-around I was thinking of.

Calvin
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by billy.becker | last post: by
2 posts views Thread by James Hull | last post: by
5 posts views Thread by Robert Oschler | last post: by
5 posts views Thread by planetbrett | last post: by
19 posts views Thread by Angus | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.