Professional Documents
Culture Documents
Synopsis: Running The Program
Synopsis: Running The Program
SYNOPSIS
#!/usr/bin/perl
#
# The traditional first program.
# Print a message.
print "Hello, World!\n";
DESCRIPTION
Running the program
Open a text editor, and type in the above program. Save it in a file named "hello". Then
open a terminal window.
Then you can run the program using either of the following:
./hello
perl hello
#!/usr/bin/perl
#!/usr/bin/env perl
or on Windows:
#!C:\Perl\bin\perl.exe
#!C:\strawberry\perl\bin\perl.exe
The first line is known as the "shebang line", and is used by UNIX-like systems to look
up the path to the Perl interpreter.
Comments
Comments in Perl always start with a '#' character:
Statements
Statements always end with a semicolon in Perl:
print 'hello';
It is possible to have more than one statement on a single line, but generally this would
not be very readable.
use strict;
use warnings;
These are strongly encouraged for all Perl programs - they tell the Perl interpreter to
check for programming errors like undeclared variables.
In this case, the double-quoted string "Hello, World!\n" is being printed. You should see
that the "\n" sequence does not appear on the console - it is used to mark the end of a
line. Double-quoted strings can contain various other escape sequences.
SEE ALSO
Perl::Tutorial
This documentation is free software; you can redistribute it and/or modify it under the
same terms as Perl itself.