in reply to Perl in C#

I've had some recent success using the Microsoft Script Control to host Perl inside my C# application.

To embed a Perl interpreter in a C# program, add a reference to the COM object "Microsoft Script Control 1.0" and write code like this:


MSScriptControl.ScriptControlClass Interpreter; Interpreter = new MSScriptControl.ScriptControlClass(); Interpreter.Language = @"PerlScript"; string Program = @"reverse 'abcde'"; string Results = (string)Interpreter.Eval(Program);

The above is equivalent to the following Perl script, which embeds a Perl interpreter within a Perl interpreter:


use Win32::OLE; my $Interpreter; $Interpreter = Win32::OLE->new('ScriptControl'); $Interpreter->{Language} = 'PerlScript'; my $Program = "reverse 'abcde'"; my $Results = $Interpreter->Eval($Program);

This technique can also embed JScript in C#, VBScript in Perl, PerlScript in Visual Basic, etc. etc. The host can pass COM objects to the interpreter, through which the interpreter can call functions in the host.

There's a newer C# interpreter-embedding system called "Visual Studio for Applications," or "VSA," but it's more complicated to use, and I'm not sure if it supports Perl yet.

Another technology called "Windows Script Components," or "WSC," trivializes wrapping scripts in COM interfaces. Using WSC one could quickly write a library in Perl, and call it from C++ or C#.

The library could later be rewritten in C++ or C# (or JScript or VBScript) without recompiling the applications that use it.