in reply to Re: Answer: how do i push an array into the perl stack in C prog before calling perl_call_pv
in thread how do i push an array into the perl stack in C prog before calling perl_call_pv

To emulate my_function("string1",@arr1,@arr2,"string2",@arr3) you just need to XPUSH the string, then XPUSH each of the elements of @arr1 (you don't need to build an array), then XPUSH each of the elements of @arr2, then XPUSH the next string, then XPUSH each of the elemnts of @arr3.

That is, in this code:

my @arr1= qw(A few things); my @arr2= qw(Two vals); my @arr3= (1,2,3); my_function("string1",@arr1,@arr2,"string2",@arr3); my_function(qw(string1 A few things Two vals string2),1,2,3);
the last two lines are the same (unless my_function has a prototype).

        - tye (but my friends call me "Tye")
  • Comment on Re: Re: Answer: how do i push an array into the perl stack in C prog before calling perl_call_pv
  • Select or Download Code

Replies are listed 'Best First'.
Re: Re: Re: Answer: how do i push an array into the perl stack in C prog before calling perl_call_pv
by ragu (Initiate) on May 08, 2001 at 12:30 UTC
    hi, in that case how wld the perl subroutine demarcate the two arrays arr1 & arr2. ie if we have arr1=(1,2) and arr2=(3,4) how wld the perl subroutine know that arr1's contents ends at 2 and arr2 ends at 4 as i would be doing only XPUSH of 1,2,3,4 before calling the sub through perl_call_pv. any help would be greatly appreciated . thank you ragu

      That is the point: It wouldn't. I suggest you read more about Perl if you think that it would. For example, if you have Perl installed, type "perldoc perlsub" for lots of information about Perl subroutines and how to call them.

              - tye (but my friends call me "Tye")
        hi,
        sorry for my persistence.i'm kind of stuck because of this and i need to find a solution. though i am not a perl expert,i do know about basics of todays trend of languages. using reference mechanism i can do this in perl(below).Is it possible to pass this reference if i were to call this sub 'call()' from a C prog after XPUSH'ing the arguments into the perl stack. please do reply.
        #begin #!/bin/perl @xyz=(abcdefghij,xyz,sdfakjsadfk); @abc=(123,345,567); &call("string1",\@xyz,\@abc,"string2"); sub call { $w=$_[0]; $x=$_[1]; $y=$_[2]; $z=$_[3]; foreach (@$x){ print "$_ "}; print "\n"; foreach ($w){ print "$_ "}; print "\n"; foreach (@$y){ print "$_ "}; print "\n"; foreach ($z){ print "$_ "}; print "\n"; } #end
        thank you
        ragu

        Edit by tye