Perl · Lesson 1 · On the house

Hello, Perl

Shebang, print, .pl, perl file.pl. Lesson 1 is free — on the house.

Lessons · Perl · Lesson 1 of 10 · On the house

Hello, Perl

Shebang, print, .pl, perl file.pl.

Illustration for Perl
Lesson 1 is on the house.

A Perl 5 script is plain text. The first line is often a shebang so the OS can find the interpreter: #!/usr/bin/env perl. On Windows you usually run perl hello.pl explicitly; the shebang still documents intent.

print "hello\n"; writes text to standard output. Statements end with a semicolon. Double-quoted strings interpret escapes like \n; single-quoted strings stay mostly literal (next lessons).

Save source as a .pl file (or .pm for modules later). From a terminal with Perl installed, run perl hello.pl. perl -v prints the interpreter version — modern introductory work targets Perl 5.

Unlike Python, there is no required indentation for blocks yet, and unlike JavaScript there is no console.log. Start with print and a working shebang path.

Misses: writing print("hello") as the only style (parentheses are optional for builtins), saving as .py, calling node file.pl, or forgetting the semicolon after print.

hello

#!/usr/bin/env perl
print "hello\n";
Match this when you type.

Quiz

What shebang commonly starts a portable Perl script?

Quiz

Which statement writes text to standard output?

Quiz

How do you run a Perl file from the CLI?

Quiz

What file extension do Perl scripts normally use?

Check

Match the still for: Hello, Perl.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.