Ad space (banner)
Lesson 3 / 20

Variables (scalar variables, $)

This lesson covers the scalar variable, Perl's basic kind of variable.

A variable holding a single value — a number, a string — is written $name. That $ is a big part of how Perl looks.

The sample code declares two variables, my $name = "Alice"; and my $age = 14;, and embeds them directly inside a string to print.

A common early stumble is forgetting my. It is the keyword that declares a variable fresh at that point, and leaving it out risks sharing a value somewhere you did not intend.

In professional work, the fact that every variable name carries a sigil — $, @, or % — is distinctive to Perl, and tells you the kind of variable (scalar, array, hash) from the name alone.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Perl directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)