Examining PerlCOM
by Mike McMillan


Listing One
objPerl.EvalScript " sub my_greet { "   & _
                   "    my $name = shift; "     & _
                   "    return qq[Hello, $name.]; } "
strName = "Charlie"
MsgBox objPerl.my_greet(strName)

Listing Two
Dim objPerl As Object
Set objPerl = CreateObject("PerlCOM.Script")
objPerl.EvalScript (" sub str_split { " & _
                    "  $string = 'Perl,C,Java,C++';" & _
                    "  my @languages = split(/,/, $string);" & _
                    "  return \@languages; } ")
arrayLangs = objPerl.str_split()
strLangs = ""
For x = 0 To UBound(arrayLangs)
   strLangs = strLangs & arrayLangs(x) & Chr(13) & Chr(10)
Next x
MsgBox strLangs

Listing Three
My %wizards = (
   C     => 'D. Ritchie',
   Java => 'J. Gosling',
   Perl => 'L. Wall',
);
print $wizards{"Perl"} 

Listing Four
Dim objPerl As Object
Set objPerl = CreateObject("PerlCOM.Script")
objPerl.EvalScript _
    " sub build_hash { " & _
    "    my %wizards = ( 'C'    => 'D. Ritchie', " & _
    "                    'Java' => 'J. Gosling', " & _
    "                    'Perl' => 'L. Wall'); " & _
    "    return \%wizards } "
Dim oHash As Object
Set oHash = objPerl.build_hash
MsgBox oHash.Get("Perl")

Listing Five
Dim objPerl As Object
Set objPerl = CreateObject("PerlCOM.Script")
Set objWizards = objPerl.CreateHash
objWizards.C = "D. Ritchie"
objWizards.Java = "J. Gosling"
objWizards.Perl = "L. Wall"
MsgBox objWizards.Get("Java")

Listing Six
Dim objHash As Object
Dim arrayPair 
Set objHash = objPerl.CreateHash
objHash.C = "D. Ritchie"
objHash.Java = "J. Gosling"
objHash.Perl = "L. Wall"
objHash.Set "Fortran", "J. Backus"
arrayPair = objHash.Each()
Do While (Not IsEmpty(arrayPair))
   List1.AddItem arrayPair(0) & " => " & arrayPair(1)
   arrayPair = objHash.Each()
Loop

Listing Seven
Dim objPerl As Object
Set objPerl = CreateObject("PerlCOM.Script")
Set objWin32 = objPerl.UsePackage("Win32")

Listing Eight
strUserName = objWin32.LoginName
strComputerName = objWin32.NodeName
strInfo = "User name: " & strUserName & Chr(13) & Chr(10)
strInfo = strInfo & "Computer name: " & strComputerName
MsgBox strInfo, , "User Information"

Listing Nine
Dim objPerl As Object
Set objPerl = CreateObject("PerlCOM.Script")
Set objFileHdl = objPerl.CreateObject("FileHandle", "new")

Listing Ten
strFileName = "c:\sample.txt"
If objFileHdl.open(strFileName) = 1 Then
   For x = 1 To 4
      objPerl.EvalScript "$dept = '';"
      objPerl.dept = objFileHdl.getline
      objPerl.EvalScript "$dept =~ s/dp/cis/;"
      List1.AddItem objPerl.dept
   Next x
   objFileHdl.Close
End If




2


