embeding perl in C++

P

Peng Yu

Hi,

It seem libperl can be used to embed perl in C++. But that was
developed long ago and is for C. I'm wondering if there are any new
and better library to embed perl in C++.

Thanks,
Peng
 
M

Mirco Wahab

Peng said:
It seem libperl can be used to embed perl in C++. But that was
developed long ago and is for C. I'm wondering if there are any new
and better library to embed perl in C++.

On the one hand, embedding *modern* Perl (5.10) is straight-
forward and easy if you know the pitfalls. On some projects,
I link the perl core to C++-programs, this works fine in Visual
Studio 6 up to Visual Studio 9 without any problems so far (using
the Activeperl distribution, others might work too). Under Linux,
the path to success is even simpler, just use the appropriate
Perl-Modules which support the embedding process (ExtUtils::Embed,
http://search.cpan.org/~rgarcia/perl-5.10.0/lib/ExtUtils/Embed.pm).

On the other hand, after the advent of the boost libraries
(e.g. Boost::Regex), there is (for me at least) dwindling
need to use this approach at all.

What do you want to use it for?

Regards

Mirco
 
P

Peng Yu

On the one hand, embedding *modern* Perl (5.10) is straight-
forward and easy if you know the pitfalls. On some projects,
I link the perl core to C++-programs, this works fine in Visual
Studio 6 up to Visual Studio 9 without any problems so far (using
the Activeperl distribution, others might work too). Under Linux,
the path to success is even simpler, just use the appropriate
Perl-Modules which support the embedding process (ExtUtils::Embed,http://search.cpan.org/~rgarcia/perl-5.10.0/lib/ExtUtils/Embed.pm).

On the other hand, after the advent of the boost libraries
(e.g. Boost::Regex), there is (for me at least) dwindling
need to use this approach at all.

What do you want to use it for?

I want to use it for processing text files. I feel that for certain
applications in text processing, writing perl code is much faster than
writing the equivalent C++ code. For example, I have a text file, who
is sorted based on the second to last column (called column X for
short), but there is no blank lines. Let's call the lines of the same
column X as a group. I would like to append the first line of each
group to the end of it and then add a blank line after the appended
line.

This can be done in just a few line of perl code (as follows), but it
would need much longer C++ code. In terms of program productivity,
using perl shall be much better than using C++ in text processing
applications. Using Boost::Regex still requires writing more code.
Therefore, I'm looking for embedding perl in C++.

perlembed is for C. Is any other packages that for embedding perl in C+
+? Although C is a subset of C++, my impression is that a package
design for C++ would better than a package designed for C in C++. For
example, boost.python is developed even there is a package to embed C
in python.

#!/usr/bin/perl

while (<>)
{
@data = split;
if (!defined($last_column)) {
$first_line = $_;
$last_column = $data[$#data - 1];
}
if ($data[$#data - 1] != $last_column) {
$last_column = $data[$#data - 1];
print "$first_line\n";
$first_line = $_;
}
print $_;
}
print "$first_line\n";
 
M

Mirco Wahab

Leon said:
Actually I'm working on just that!
Fine!

It's similar to boost.python,

I hope not ;-)
but in an earlier stage. Mail me if you're interested.

Boost_Python is, IIRC, for exposing C++ functions
to a Python program and not for using Python within
a C++ program. It does what SWIG does - but hides that
process it behind an interface.

(I don't get it - what this is all about and what this
one has to do with Boost, but YMMV ...)

Regards

M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top