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
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:
#!/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.
use strict;
: This is a pragma to enforce strict variable declaration, which can help catch some common programming errors.
use warnings;
: This enables warnings to catch potential issues in your script.
print "Hello, World!\n";
: This line prints the string "Hello, World!" to the console, followed by a newline character (\n
).
To execute the program:
hello.pl
.chmod +x hello.pl
./hello.pl
Alternatively, you can run it using the Perl interpreter directly, without needing the shebang line or execute permissions:
perl hello.pl