Hi,
I have problems with eval when I want to call a procedure inside eval which passes a argument.
This line fails when i pass $firstname. If I call without argument it's fine.
my $code = eval "sub {get_lastname($firstname);}";
Error:
Undefined subroutine &main:: called at V:\BERB_view\FINANCE_SUPPORT\Tools\Ration
al\ClearCase\scripts\bin\eval_test.pl line 7.
Please don't reply about the sense of the sample as it's just for evaluation reason to find out what I can do with eval.
Full Sample:
my $code = eval "sub { print }";
&$code;
$lastname=get_lastname("Robert");
print ("LastName: $lastname\n");
$firstname="Peter";
my $code = eval "sub {get_lastname($firstname);}";
$lastname=&$code;
print ("LastName: $lastname\n");
sub get_lastname ()
{
$firstname=$_[0];
print ("FirstName:$firstname\n");
return "Armadillo" if ($firstname eq "Robert");
return "Walls" if ($firstname eq "Peter");
}
I have problems with eval when I want to call a procedure inside eval which passes a argument.
This line fails when i pass $firstname. If I call without argument it's fine.
my $code = eval "sub {get_lastname($firstname);}";
Error:
Undefined subroutine &main:: called at V:\BERB_view\FINANCE_SUPPORT\Tools\Ration
al\ClearCase\scripts\bin\eval_test.pl line 7.
Please don't reply about the sense of the sample as it's just for evaluation reason to find out what I can do with eval.
Full Sample:
my $code = eval "sub { print }";
&$code;
$lastname=get_lastname("Robert");
print ("LastName: $lastname\n");
$firstname="Peter";
my $code = eval "sub {get_lastname($firstname);}";
$lastname=&$code;
print ("LastName: $lastname\n");
sub get_lastname ()
{
$firstname=$_[0];
print ("FirstName:$firstname\n");
return "Armadillo" if ($firstname eq "Robert");
return "Walls" if ($firstname eq "Peter");
}