Concepts / Your first script: hello world
Subtitles of the Movie
Now that we've gone through a list of the basic equipment that you will need to start building your Perl scripts, let's jump in with a practical example. Before we do that though I should draw a distinction between different ways of testing your Perl scripts. The first way is directly from the command line. Another way is to use a web browser to pass a request to our web server, which then runs a script and returns the output to the browser, as we saw in the last movie. Let's take a look first of all at our text editor. And we are going to write our first Perl script. In the long tradition of programming instruction, your first script is going to simply output the words, 'hello world' to the user, and who am I to break that tradition. We are using the Windows system here to create our first script, and there are some slight differences in the way that we put together the script, even though it's a very simple one, between Windows and other systems. And we are going to look at windows in this movie, and then we are going to be looking at uploading our scripts, to a Linux server in the next movie. For now, the script I am going to write is very simple, simply print 'hello world' and I am enclosing that hello world in single quote marks, with a semicolon at the end. I won't explain what the different parts of this line of code mean, at the moment. All we're interested in now is simply getting a script to work, and to display within our system. So let's save this now. And we are going to save this to, well it can be absolutely anywhere we want to save it, so let's just save it in my documents and we are going to call it 'hello.pl'. Now this is another Windows specific thing, the .pl extension is an extension to maintain a file association between Perl script files and the Perl executable. So we save our file with this file name, and then the Windows operating system is able automatically to tell that this file is to be used by running Perl. In order to see this script work, let's open up our command prompt. Because we are using Windows this is the DOS prompt, so we are going to go to wherever we saved it to, so let's take a look at directories there. That gets us to my documents, and we called it 'hello.pl'. You know there's a slight pause there before the output was returned, that was windows invoking the Perl executable running the script. And our first little Perl program has worked fine, and the words 'hello world' has been returned to us.
Tutorial Information
| Course: | Perl Fundamentals |
| Author: | Joshua Mostafa |
| SKU: | 33403 |
| ISBN: | 1-9320-7215-2 |
| Release Date: | 2002-12-19 |
| Duration: | 7.5 hrs / 113 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 