Perl Tutorial

Fundamentals

Input and Output

Control Flow

Arrays and Lists

Hash

Scalars

Strings

Object Oriented Programming in Perl

Subroutines

Regular Expressions

File Handling

Context Sensitivity

CGI Programming

Misc

Hello World Program in Perl

A simple "Hello World" program in Perl looks like this:

#!/usr/bin/perl
use strict;
use warnings;

print "Hello, World!\n";

Here's a brief breakdown of what each line does:

  1. #!/usr/bin/perl: This is called a shebang line. It tells the operating system to execute the script with Perl. This is primarily useful if you're running the script from a Unix-like environment.

  2. use strict;: This is a pragma to enforce strict variable declaration, which can help catch some common programming errors.

  3. use warnings;: This enables warnings to catch potential issues in your script.

  4. print "Hello, World!\n";: This line prints the string "Hello, World!" to the console, followed by a newline character (\n).

To execute the program:

  1. Save the code in a file, say hello.pl.
  2. Provide execute permission (in Unix-like systems) with: chmod +x hello.pl
  3. Run the program with: ./hello.pl

Alternatively, you can run it using the Perl interpreter directly, without needing the shebang line or execute permissions:

perl hello.pl