472,950 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

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 4094
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: billy.becker | last post by:
I need to save a wav file that is HTTP POSTed to a php page. What does PHP5 do automatically to a POSTed variable when it puts it in the $_POST superglobal array? I haven't been able to find any...
2
by: James Hull | last post by:
Hi All: I am new in the Perl world. So far I have installed cygwin and Perl 5.8.0 along with Perl DBI and DBD::Oracle modules. NowI am trying to install Perl Tk on my PC (Windows 2K). I have...
20
by: TTroy | last post by:
Hello, I have found some peculiar behaviour in the fgets runtime library function for my compiler/OS/platform (Dev C++/XP/P4) - making a C console program (which runs in a CMD.exe shell). The...
5
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
5
by: nagrik | last post by:
Hello group, Last week I picked up a thread, which pointed out that if a copy constructor is created with pointers instead of reference, there is a danger of it going in infinite recursion. ...
5
by: planetbrett | last post by:
I have read through php.net manuals and have not see any mention about what these operands actually do. I have seen them used in a bunch of different code lately and don't really understand. ...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
0
by: srinu123 | last post by:
Hi all, I am tring the install perl module(GD-2.35) on my linux machine.But i am getting some error...Please find the error below... D.xs:1450: invalid lvalue in assignment GD.xs:1450:...
3
by: andrewkl | last post by:
hi, I have the following Perl code that inserts a string to an Oracle DB via a stored procedure: #!/usr/local/bin/perl ## Perl v5.8.6 built for sun4-solaris use strict; BEGIN...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.