Perl · Course navigation

Perl Basics

Declare a scalar and print it.

On this page

The concept

A scalar variable starts with $. strict and warnings catch common mistakes. print writes the interpolated string.

Code example

Perl
use strict;
use warnings;
my $name = "Ada";
print "Hello, $name\n";
Output
Hello, Ada

Follow the code

Open the walkthrough to inspect the example one step at a time.

Show guided walkthrough
Guided walkthroughReady
1use strict;
2use warnings;
3my $name = "Ada";
4print "Hello, $name\n";

Follow the example

Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.

View the complete dry-run table
Prepared trace of the published program. Some rows group repeated iterations.
Step / lineWhat happensState after stepOutput so far
Declare a scalar variable.$name = "Ada"
—
Interpolate name and print a newline.$name = "Ada"
Hello, Ada

Behind the scenes

How Perl processes this code

Perl compiles the script internally before executing it. strict and warnings help identify mistakes.