Surya
Surya

Reputation: 1197

Read perl script from c++

I've to read and parse HTML file and populate a data structure (in C++). I'm planning to do the parsing using perl (so I can use some other perl modules.). My requirement is this.

  1. Get the file from gui (C++ code)
  2. Pass it to perl.
  3. Parse file on perl side (perl script using some other perl modules), populate the C++ structure
  4. Continue working on C++ side with the populated structure.

I'm reading about extending and embedding perl, but unable to figure out the correct procedure. Any help would be greatly appreciated.

Upvotes: 3

Views: 910

Answers (3)

David Hammen
David Hammen

Reputation: 33116

Yet another alternative is to have perl drive your C++ code. Write a function that has a perl-side implementation that calls a corresponding C-side implementation. Do man perlxs and perlxstut for more info.

Edit: Or read it online at http://perldoc.perl.org/perlxs.html and http://perldoc.perl.org/perlxstut.html.

Upvotes: 1

Robᵩ
Robᵩ

Reputation: 168626

I've used swig to connect C++ and Python. The documentation says it works for Perl, also.

Upvotes: 3

DavidO
DavidO

Reputation: 13942

In your reading did you find perlembed in Perl's documentation? That's the definitive resource for learning how to embed Perl in a C/C++ program. The author of the document was one of the original mod_perl developers, I believe.

I don't think that embedding Perl for a trivial task would be the easiest solution when compared to doing a system call to perl and parsing the result, but for more involved needs it's certainly a solution.

Upvotes: 4

Related Questions