Function run_script(q As String) As String
' To use this sub/function you must have
' Perlscript installed* and then register the
' Microsoft Script Control 1.0 (MSSCRIPT.OCX)
' which you must register from the Tools-References
' menu of the VBA editor.
' * standard in ActiveState's ActivePerl distribution
'requires table named "perl_scripts" with fields
'script_name (text)
'script (memo)
On Error GoTo run_script_error
Dim db As Database
Set db = CurrentDb
Dim scripts As Recordset
Set scripts = db.OpenRecordset("perl_scripts", dbOpenSnapshot)
Dim finder As String
finder = "script_name='" & q & "'"
scripts.MoveFirst
scripts.FindFirst (finder)
If scripts.NoMatch Then
Debug.Print "Script " & q & " not found."
Err.Raise 448
End If
Dim ps As String
ps = scripts("script")
Dim perl As New ScriptControl
perl.Language = "PerlScript"
run_script = perl.Eval(ps)
Exit Function
run_script_error:
MsgBox ("Error running Perl script: " + Error$)
run_script = False
End Function
####
use strict;
sub foo {
my $name = shift;
return "Hello, $name.\n";
}
sub bar {
my $name = shift;
return "Good-bye, $name!\n";
}
my $return = foo("World") . bar("Cruel World");
return $return;
##
##
Sub test_run_script()
Debug.Print run_script("Perl Test")
End Sub