Basic Syntax in Perl
In this tutorial, we will learn the basic syntax of Perl language. We will go through the key components of a simple Perl program.
Perl Program
#!/usr/bin/perl
use strict;
use warnings;
print "Hello, World!\n";
Output
Hello, World!
Basic Syntax of a Perl Program
#!/usr/bin/perl
This line is called the shebang line. It tells the system that this file should be executed using the Perl interpreter located at/usr/bin/perl
.use strict;
This line tells Perl to enforce strict programming rules, helping catch common mistakes.use warnings;
This line enables warnings, which provide additional information about potential issues in the code.print "Hello, World!\n";
This line prints the string "Hello, World!" to the standard output (usually the screen). The\n
is an escape sequence that adds a new line after the text.
Key Points to Remember
- All Perl statements must end with a semicolon (
;
). - The shebang line is optional on Windows but necessary on Unix-like systems to locate the Perl interpreter.
- Comments can be added using
#
for single-line comments. - Perl is case-sensitive, meaning that
Print
andprint
would be considered different identifiers.