Running Perl Scripts on Windows Systems

This section provides a tutorial example on how to run Perl scripts with ActivePerl on Windows systems. To make a Perl script file executable, you need to set the script file name extension to '.pl'.

There are many ways to run Perl scripts with ActivePerl on Windows:

1. Run the "perl" command with the Perl script included in the command line. For example, enter the following command line in a command window:

C:\herong>perl -e "print 'Hello world!';"
Hello world!

Another example:

C:\herong>perl -e "for ($i=0; $i<10; $i++) {print \"$i\n\";}"
0
1
2
3
4
5
6
7
8
9

This is a cool way to run a Perl script quickly. But you can only run programs that are small enough to fit into one command line.

Also note that double quote (") is used to put the entire program code as one command line parameter. Any double quote inside the program needs to be protected as (\").

2. Run the "perl" command with the Perl script supplied from the standard input steam. For example, enter "perl" in a command window. Then enter the program source code followed by Control-Z, which is the End Of File (EOF) indicator:

C:\herong>perl
$s=0;
for ($i=0; $i<10; $i++) {
   $s+=$i;
}
print "$s\n";
^Z
45

Obviously, you can enter a much longer script in this way. But the script is not save permanently.

3. Run the "perl" command with the Perl program supplied in a file. For example, enter the following program in a file called hello.prg:

   print "Hello world!\n";

Then enter the following command in a command window:

C:\herong>perl hello.prg
Hello world!

This is how you normally run Perl programs.

4. Run Perl program files as commands. You can do this, only if you name your Perl script files with ".pl" as file name extension, because ".pl" has been associated with the "perl" command during the installation. For example, enter the following program in a file called hello.pl:

   print "Hello world!\n";

Then enter the following command in a command window:

C:\herong>hello.pl
Hello world!

It works!

Last update: 2014.

Table of Contents

 About This Book

 Perl on Linux Systems

ActivePerl on Windows Systems

 What Is ActivePerl?

 Installing ActivePerl v5.18.1 on Windows Systems

Running Perl Scripts on Windows Systems

 Installing ActivePerl v5.8.8 on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Converting Perl Script to Executable Binary

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server

 CGI.pm Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 References

 PDF Printing Version