My First Perl Program
Program that prints out Hello, World! (let's call our file hello.pl):
#!/usr/bin/perl
print "Hello, World!\n";
The first line signifies where the perl interpreter resides on the host system. This is usually /usr/bin/perl on Linux systems and /bin/perl under *NIX systems.
The next statment is a simple print statement. That's it.
Switches
The perl interpreter has useful switches. The -c switch lets perl check for syntax only, without running the actual program.The -w turns on all useful warnings. You should ALWAYS develop your programs under -w.
So how would you actually run this program? You could run it as:
$perl -w hello.pl
or we could make the perl file executable, by using the chmod command:
$chmod 700 hello.pl
$./hello.pl
How do I issue the -w flag? Simple, put it in the perl line at line
#!/usr/bin/perl -w.
A comment in Perl begins with #.