Perl - Part 1 of 25 parts.
[home] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]
Views differ on Perl. Greatly.
Created by Larry Wall, he called it the Practical Extraction and Report Language. Others call it the Pathetically Eclectic Rubbish Lister. A bit of a difference in attitude, you'll agree.
But there's hardly a webserver (or indeed any other significant server) in the world that doesn't use PERL somewhere for something. So love it or hate it, you're going to have to respect it. Tough.
"Hello World"
The first program traditionally written by all programmers (no matter how expert) in a new language is the "Hello World" program. This program writes Hello World on screen and then stops. Why do we write such a daft program? Well for a start it's not daft; it serves a very valuable function. Here's a quote from the wikipedia:
"A "hello world" program can be a useful sanity test to make sure that a language's compiler, development environment, and run-time environment are correctly installed. Configuring a complete programming toolchain from scratch to the point where even trivial programs can be compiled and run can involve substantial amounts of work. For this reason, a simple program is used first when testing a new tool chain."
As a matter of fact, go read the whole thing. It's good for you and has useful links. Better still read the FAQ - it's mind-blowing.
"Hello World" becomes hello.pl
This a LINUX/UNIX version of the program. Get it running then have fun playing around to make it look different:
#!/usr/bin/perl
print "Hello World!";
#!/usr/bin/perl
print "Hello World!";
The above program should display the words Hello World! and immediately exit. If you find that the program doesn't run, or runs but doesn't do what you expected of it, check what you've typed: programming languages tend to be quite precise and the slightest error can lead to unexpected outcomes, at the least, failure to execute properly.
Even if the program does run as expected, you should notice that the output text is lumped onto the same line as the command prompt. To make the program a little more attactive we can use an escape sequence to move onto the next line after printing the required text. The escape code for this is \n (where n stands for new line). Edit your program again until the modified code looks like this:
#!/usr/bin/perl
print "Hello World!\n";
And yes, that is all there is to this little traditional program that has probably been created and run more times than any other program. The fun will coming from entering it and getting it to run.......