Creating a Perl program

Home

Perl programs are generally created with a .pl extension.

Note, if you have installed Perl somewhere other than C:\Perl, then substitute your path for C:\Perl.

Open MS-DOS. 
Type cd C:\Perl\bin. this is where Perl is. Change path to cgi-bin?
Type edit myprog1.plthis should open up the text editor
Type #!/usr/bin/perlthis is the path where Perl is to be found on the server
Type: print "My first program!";this is the statement to be executed
Save the file<file><save>
Exit<file><exit>
Type: perl myprog1.plthe text 'My first program' should appear.

On a Unix system, if you add execute permission to the file with a command such as $ chmod +x prog1.pl, the interpreter file can then be executed directly from the command line without including 'perl', for example: $ prog1.pl.

Type edit myprog2.plthis should open up the text editor
Type the following: 
$myvariable = "mine all mine"; 
if ($myvariable eq "mine all mine") { 
print "You're not having it!"; 
}  
Save the file<file><save>
Exit<file><exit>
Type: perl myprog2.plthe text 'You're not having it!' should appear.

You can also type programs in using a text editor (or a word processing program if you save as text), creating files with a .pl extension.

Back to top     Home     Serious Stuff

© 2001. Copyright Sue Nethercott.