> It makes no difference whether $VAR is declared with 'my' or not. In > either case C's func() *can't* see it. You need to pass $VAR as an > argument to func().
Thanks, buy this isn't quite right. If it is not my'd, then it is available via either the package stash, or by just use get_sv. This works fine: $VAR = "abc"; use Inline C => <<EOF; void func() { SV * VAR = get_sv( "VAR", FALSE ); if( VAR ) { printf("VAR = %s\n", (char*)SvPV(VAR,PL_na)); } else { printf("VAR is NULL\n"); } } EOF func(); If you 'my' the variable, then get_sv returns NULL. > If you specifically want to pass the argument as an SV* instead of a > char*, then you can change func() to: I dont *want* to pass anything, I just want to use it since it should be in scope, I just dont know how to grab it inside perl. > Perhaps what you *really* want to know is how to embed a perl variable > in C ? If so, then 'perldoc perlembed' is about all that *I* can offer. > (There might even be something in the Inline C Cookbook on this - > anyway, if you haven't already, take a look at 'perldoc > Inline::C-Cookbook'.) Thanks, I already checked out the cookbook, perlguts, perlapi, perlxs and perltut. It does not seem to be covered anywhere. In Adv. Perl Prog. it did mention function "padlists" which hold my'd variables, but I dont know how to access the padlist or if that is the even right approach. I did manage to get what I wanted by using eval_pv, although this should be slow. Just wondering how to get the value without the eval since I doubt it is necessary: my $VAR2 = "abc"; use Inline C => q{ void func2() { SV * VAR2 = eval_pv("$VAR2", FALSE); if( VAR2 ) { printf("VAR2 = %s\n", (char*)SvPV(VAR2,PL_na)); } else { printf("VAR2 is NULL\n"); } } }; func2(); Thanks anyway! -Cory