On Tue, Dec 02, 2003 at 05:40:14PM -0600 Dan Muey wrote:
> What I was wondering about was how to execute some perl code *inside*
> the c program instead of takign it via ARGV. I think eval_pv and
> eval_sv have somethgin to do with it but I'm a bit cloudy there.
> Since I don't know hardly anythgin about C I'll illustarte it in Perl.
>
> my $perlcode = <<CODE;
> # instead of getting this via command line argument
> sub simplepage {
> my $name = shift || 'world';
> use CGI qw(header param);
> print header()
> print "I am perl hear me roar $name\n";
> print insult();
> }
> sub insult { return "So is ytour mother\n"; }
> return simplepage(param('name'));
> CODE
>
> printf eval_pv($perldoc);
>
> Basically execute bunch of code, from a one liner to a bunch of lines,
> that basically ends with one return value(an html webpage) and then
> print that value out.
This can't work because you cannot have return-statements outside of
subroutines in Perl. However, why not just leave the 'return' off:
my $perldocde = <<CODE;
...
simplepage(param{name});
CODE
And from C:
STRLEN n_a;
char *string;
SV *ret;
...
ret = eval_pv(perlcode, TRUE);
string = SvPV(ret, n_a);
eval_pv() returns the last statement evaluated as a SV.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]