Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

embeding perl in C++

0 views
Skip to first unread message

Peng Yu

unread,
Jul 3, 2008, 2:00:58 AM7/3/08
to
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

Mirco Wahab

unread,
Jul 3, 2008, 2:53:52 AM7/3/08
to

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

Sherman Pendley

unread,
Jul 3, 2008, 11:18:38 AM7/3/08
to
Peng Yu <Peng...@gmail.com> writes:

Libperl isn't a separate library for embedding - it *is* Perl, and
/usr/bin/perl is simply an application that uses it. There's only one
libperl, and that's the one included with Perl.

sherm--

--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net

Peng Yu

unread,
Jul 3, 2008, 1:38:26 PM7/3/08
to
On Jul 3, 1:53 am, Mirco Wahab <wa...@chemie.uni-halle.de> wrote:
> Peng Yu wrote:
> > 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?

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";


Leon Timmermans

unread,
Jul 8, 2008, 1:49:59 PM7/8/08
to

Hi,

Actually I'm working on just that! It's similar to boost.python, but in
an earlier stage. Mail me if you're interested.

Regards,

Leon

Mirco Wahab

unread,
Jul 8, 2008, 6:19:44 PM7/8/08
to
Leon Timmermans wrote:
> On Wed, 02 Jul 2008 23:00:58 -0700, Peng Yu wrote:
>> 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++.
>
> 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.

0 new messages