Hi,
I am trying to convert a small perl program to CamelBones, but am
having some problems. Here's a snippet of the original script:
....
my $num = 0;
print "Give a number ";
$num = <STDIN>;
chomp( $num );
initList() # sets values in myList
iterate();
sub iterate
{
if ( @_ >= $num )
{
my $sum = 0;
$sum += $_ for @myList[@_];
... # do some calculations here
return;
for my $i ( ( @_ ? $_[-1] + 1 : 0 ) .. ( @myList -
$num + @_ ) )
{
iterate( @_, $i );
}
}
}
So the code iterates the myList $num times. When exectued in the
shell, this works OK.
Now here's my attempt for CamelBones. I am using the
MyControllerWindow.pm file, and have created an action-button called
'iterate' that should invoke the subroutine. I also have a textfield
where the user can type in $num.
sub iterate
{
my ( $self, $sender ) = @_;
my $num = $self->{'NumberField'}->intValue;
if ( @_ >= $num )
{
my $sum = 0;
$sum += $_ for @myList[@_];
... # do some calculations here
return 1;
}
for my $i ( ( @_ ? $_[-1] + 1 : 0 ) .. ( @myList - $num + @_ ) )
{
iterate( @_, $i );
}
return 1;
}
Using NSLog(), I verified that myList and num are OK, and that the
code actually enters iterate(). I suspect the problem lies in the use
of @_ and/or $_ - maybe CamelBones uses that internally?
Can anyone spot an error in my code? It's been quite a while since I
wrote this, and haven't done a lot of perl, so maybe it's just a very
obvious error.
thanks,
- Koen.
- Re: converting script to use with CamelBones Koen van der Drift
- Re: converting script to use with CamelBones Koen van der Drift
