Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eval error: Undefined subroutine &main:: called at eval_test.pl line 5

Status
Not open for further replies.

iamberb

Programmer
Jul 14, 2005
15
DE
When i use this:
my $code = eval "sub { return check_name(true); }";
$return=&$code;
I get error:
Undefined subroutine &main:: called at eval_test.pl line 5
but this is OK.
my $code = eval "sub { return check_name(); }";

So it must have something to do with argument passing inside eval.

What i am doing wrong ?
Thanks for your help,
robert
 
Hi,

I am kind of new to Perl and not really used to eval but I don't think I have evere seen 'true' and 'false' used in Perl code...(it is more using 0 and 1, def and undef)Can someone confirm?
What are you trying to do exactly? there is certainly another way to do that...
Why don't you call directly the subroutine and make it return 0 or 1 you test with an if statement like:
Code:
my $return=check_name($val);
if ($return) #(meaning it is true, set to 1...)
     {
..... 
     }
...
sub check_name()
     {
      my $arg=shift;
      my $ret=0;#set it to false
      if ($arg eq ...)#do your thing to check if it is true
            {
             .....
              $ret=1;
            }
       return $ret;
     }
Hopes that helps,
Eve
 
It probably has something to do with the way you are defining the check_name sub. My guess is that you have the sub defined something like:
Code:
sub check_name () {
     # ....
}

# Rather than:
sub check_name {
     # ....
}
or have an equivalent sub declaration, which imposes argument prototypes on check_name (i.e. no args). This would be why Perl can't find the sub when an argument is passed.

Post the sub def if that isn't the problem.

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top