One thing to think about is if you are running with -w or use warnings...
because the following code:

my $x = "ABC"
my $subname = "&somesub";
eval"$subname($x)";

will generate a warning or an error on use strict;

The reason is that $x is interpolated in a double string context BEFORE
being evaled...so the eval looks like
&somesub(ABC).

ABC is a bareword and therefore not allowed.  To get by this, you should
wrap strings in double quotes.

However, it seems to me that you may not even want an eval...a reference to
a subroutine would be more secure.

my $setf = \&SetFieldGG;

push( @data, $setf->($FIELD{$key}, $dataStr, $flagBold, $flagNoWord) );

To me, that is a cleaner solution.
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, January 14, 2002 3:00 PM
Subject: updated EVAL question


> *********  NOTE  ******
> ***  There was a typo in my first e-mail
> ****   But my program was spelled correctly.
> ****   I corrected the 's' and made it a capital.
> ****   Any ideas.
> ****   Thank you Tanton Gibbs for the typo tip.
>
> This is a question using eval.
>
> Below is some test code using eval.
> It worked. A function call was loaded to a variable ($func_name)
> and eval calls the function and passes the variables.
>
>
> $func_name = "&make_shift";    ## load the function call and its name
>
> push(@data, eval"$func_name(4,5,6)");    ## call function and load results
in
> @data
>
> print "This is data @data \n";       # prints "This is data help is on the
> way 1 2 3"
>
> sub  make_shift() {
>            my($a,$b,$c) = @_;
>
> print "please help \n";
> return "help is on the way $a $b $c \n";
>
> }
>
>
>
> ***************************************************
> I used the same logic at work and the eval does NOT respond.
> I used ACTIVESTATE's debuger, and it shows all variables have values,
> including the $setf, yet the eval does nothing.
>
> $setf = "&SetFieldGG";
>
> &preprint;
>
>
> sub preprint {
>
> # a lot of code
> ...
>
> push(@data, eval"$setf($FIELD{$key}, $dataStr, $flagBold, $flagNoWord)");
>
>
> }
>
> sub SetFieldGG  {       <<-- This is not called
>     local($Field, $Str, $Flag, $FlagNoWordWrap) = @_;
>
> ....
>
> }
>
>
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to