gszczesz has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl interpreter running in parallel with my C++ program. The C++ program passes code to the perl program and then receives the results. The communication is done through named pipes.

Passing the standard data such as ints, longs, doubles and strings is easy. What I can't figure out is how to receive and then send to the Perl program references.

For example, my perl code returns a hash reference. I tried having my perl program send it to my C++ program as a string, and it comes as HASH(0xXXXXX). When the C++ sends a string SV with that value back to the perl, it doesn't work. I tried having the Perl program send the SV as a long. When my C++ program sends it back to the perl program, I also ran SvRV_on to mark that the data is an RV. That didn't work either. In short, knowing that a particular RV can be represented as HASH(0xXXXXX), how can I create a new SV to become an RV pointing to that hash??? Greg

Replies are listed 'Best First'.
Re: How to extract/set RV information?
by Marshall (Canon) on Jun 09, 2009 at 05:45 UTC
    I don't have experience linking Perl "guts" to C++ "guts". I am wondering about the I/F between Perl and C++ and the functional partitioning? My first thought would be to not use any machine specific or low level stuff at all, but rather use a text based I/F protocol across these pipes.

    It would also be helpful if you could just post as simple of a set of code that you can that demonstrates the problem.

      As an example, after running some perl code and retrieving the returned SV off the stack, I can extract a long value from it by running:

      long value = SvIVx( thesv );

      If I want to pass the long value back to my perl program, I can put it inside an SV by running the following:

      SV* newsv = newSViv(long_in);

      Same goes for double and string values. It is relativelly easy to extract them form the SV, pass it along to other programs, and then put it back into an SV.

      No idea how to do the same for a reference, RV.

      Greg

        I don't have an answer right now, but I do have a recommendation: buy "Advanced Perl Programming" by S. Srinivasan. The discussion of Perl Value Types starts on page 328. HV's are discussed starting on page 337. Pages 328-350 are "not particularly easy", but are understandable with C knowledge.