Developing Webs logo
Google
Web DW-Main DW-Photoshop
Visit the message board for solutions or post a question Check out the Classes offered for free at Developing Webs Voice Chat submit a tutorial, resources, article, font for publication consideration and earn a one way link back to your site Get more specifics about the Developing Webs Voice chat room and its room members View the current news at Developing Webs alternative sites which are resources for your d3evelopment needs Join Developing Webs Chat Link to us on your web page to help support this resource! Check out Developing Webs At yahoo groups! Developing Webs Home Adobe Photoshop Tutorials Macromedia Flash Tutorials Jasc Paint Shop Pro Tutorials Adobe Illustrator Animation basics Some Basic PHP tutorials Perl Tutorials HTML Tutorials Cascading Style Sheets javascript Front Page Tutorials Macromedia Dream Weaver Tutorials dreamweaver Publishing your site, FTP, ChMod, Promotions Tools to help you create your site Free and shareware fonts to download Photographs to use in your projects Shop for your site needs Free Online classes REcommend this site to others Developingwebs Log Out Change My Account details and preferences
RSS Newsfeed
for your site
DW News
Calendar
DW Forum
Right click on button and copy shortcut

Add to My Yahoo!

Reminder
Remember to book mark this site!



Request a Tutorial

Hello World! ~ Your first Perl script

by pixelatedcyberdust, 1/13/04

In this section we will be going over the basics of setting up and running your first perl script. Before we continue, if you have not installed Perl on your system, download the latest MSI version from http://www.activestate.com under ActivePerl

1. On your desktop, Right Click and select New>Text Document. Rename the file to test.pl and click enter.  ".pl" is the Perl file extension and any text document can be saved as a .pl file.  .cgi is nothing more than a perl file written for the web, neither extension is better or worse than the other and both will work in either environment.

2. The first line of every Perl script is called the shebang line.  This line begins with the pound symbol and continues with the location of Perl on your system. If you are using Windows and did a default install, your shebang will look like this:

#!/usr/bin/perl

3. Okay, let's begin your first Perl script.  Double click on your test.pl file on your desktop, it should open up in Notepad for you.

4. Type in your shebang line on the first line and click enter a few times. On the next line, type the following line:

print "Hello World!";

To print in Perl, whether it be information to a database or to the screen, we call upon the print command. We usually use quotes around our phrase and end it with a semi-colon. Nearly ALL Perl lines will end in a semi-colon, this tells Perl that our command or line of text is complete and to begin reading the next.

5. Click on File>Save to save your script.  Open up your cmd or command prompt by click on your Start icon>Run> then type in 'cmd' if you are on Win2000+ or type 'command' if you are on an older version of windows.

6. To run a perl script from your desktop, you have to travel through the command prompt to your desktop directory.  On some version of Windows it'll open up to Desktop on default, other's (like my computer), it doesn't. 

To change a directory in this window, use 'cd'.  CD stands for 'change directory' and it lets you change up a directory or back a directory.  Here is an example of me working on Windows XP.

Opens to:               C:\Windows\Documents and Settings\
I type:                     cd desktop
Now open::            C:\Windows\Documents and Settings\desktop


To switch back a directory, you type "cd ..".  Here's another example:

Now open:            C:\Windows\Documents and Settings\desktop
I type:                    cd ..
Now open:            C:\Windows\Documents and Settings\


7. Now to run your perl script, call the PERL command followed by your file name.  If our file was test.pl, we'd type in "perl test.pl" without the quotes.

If this was successful, your program should write the phrase "HELLO WORLD!!" inside of your command window.  Congratulations, you have written your first Perl script

Now it should read HELLO WORLD! Yay!!! You now wrote your first Perl script and you'll now be losing countless of hours of sleep because of it :)

Complete example:
#!/usr/bin/perl

print "Hello world!";



"Building The Web Into a Nicer Place -- One Site At A Time"
Developing Webs Group Copyright © 2001-2014 All Rights Reserved
Privacy and Legal




iSECURE Network Security