Basic Rules and Syntax
Variables, Arrays and Hashes
Now let us move to the real part - the programming part. Ready for the "Hello World" program?
#!/usr/local/bin/perl print "Hello World";
Type this out in a text editor like notepad and save this to a file called 'hello.pl'. If you are using Linux/Unix, run the command 'perl hello.pl'. If you are using Windows and you have installed ActivePerl, just double click the file and the script will be executed by the interpreter.
OK. Lets see what the program does line by line. Most of the things I have already said in the Basics section.
Line 1 : #!/usr/local/bin/perl
This line tells the system where the perl interpreter is located. But this could be different in different systems. See where your perl interpreter is located by running the 'type perl' or 'which perl' command. This is not necessary in windows. But if you plan to make a CGI script, this line is a must if it is hosted on a Unix based server. And make sure that the first line is pointed to the correct location.
Line 2 : print "Hello World";
If you don't know what this line means, bang your head on the keyboard three times. If you do know what this line means, I will reinforce your knowledge by telling you what it does. This will Print the string "Hello World". Notice the semi-colon(;) at the end of the line? Let me tell you the rule number one of Perl : Always put the semi-colon at the end of the line. If you don't, the perl interpreter will punish you with a very strongly worded error message.
$var = <STDIN>;
This statement will get data from "Standard Input"(Keyboard) and store the data in a variable called '$var'. Please note that the STDIN must be in capital letters.
Great! Now you are a perl programmer. But you are not a CGI Joe yet. Don't know what a CGI Joe is? A CGI Joe is a hard-core CGI script programmer with all the social skills and charisma of a plastic action figure.