Here is a very simple samie script that loads the google web page, enters a query in the q edit box and clicks on the btnG submit button.
$| = 1;
my $URL = "http://www.google.com/";
$Win32::OLE::Warn = 3;
$seconds = Navigate($URL);
print "Google Page took $seconds seconds to load\n";
$seconds = ClickFormButton("btnG");
print "Query Page took $seconds seconds to load\n";
Going through the code line by line...
The use keyword in PERL tells the perl interpreter engine to use a perl module. In this case the perl module is defined by Win32::OLE. We are actually telling the interpreter to open up and be prepared to use the file named OLE.pm. In this case, the .pm extension stands for perl module.
Q. How does the perl interpreter know where to find the perl module?
A. If we open up the file named OLE.pm, the first line of code we see looks like this:
This is our clue as to how to use the file in a module. Everything has been set up properly for us when we installed active perl. Go to the command line and type the following:
perl -e "print @INC;"
This is what I get:
These are the two paths that the perl interpreter is going to look down in order to find any modules. I happen to know that the OLE.pm file lives here:
To find the module, the PERL interpreter looks down each path, adds the directory(s) before the double colons (::) and searches for the filename after the last double colon (::) and adds the extension .pm to it.
The Win32::OLE module was contributed by ActiveState, it includes a PERL extension that allows you to interact with Microsoft COM objects.