Perl Basic Syntax

Perl Basic Syntax

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

use strict;
use warnings;

print "Hello, World!\n";


Hello, World!

Basic Syntax of a Perl Program

  1. #!/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.
  2. use strict;
    This line tells Perl to enforce strict programming rules, helping catch common mistakes.
  3. use warnings;
    This line enables warnings, which provide additional information about potential issues in the code.
  4. 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 and print would be considered different identifiers.