AnyCompiler

Introduction to Perl

Perl is a dynamically typed, interpreted scripting language built from the start for text processing — reading logs, slicing up reports, gluing other programs together. It has no compile step: a Perl file runs top to bottom the moment you execute it.

Its most distinctive feature is the sigil — the punctuation character at the front of every variable name. $name is a scalar (a single value: a string, a number, or a reference). @name is an array (an ordered list). %name is a hash (key-value pairs). The sigil tells you the data type, not a declaration keyword — nothing else on this site works this way. Python, JavaScript, TypeScript, Rust, Go, Java, C, C++, C#, Kotlin, Swift, and Bash all tie a variable's shape to its declared type or to one uniform variable syntax; none of them change a variable's meaning based on a leading punctuation character the way Perl does.

A quick preview

Here's a real Perl program, executed for real on this page's own compiler — not a mockup:

my $language = "Perl";
my @sigils    = ('$', '@', '%');
my %means_what = ('$' => 'a single scalar value', '@' => 'an array', '%' => 'a hash');

print "$language uses sigils to tell you the data type.\n";
for my $sigil (@sigils) {
    print "  $sigil means $means_what{$sigil}\n";
}
Output
Perl uses sigils to tell you the data type.
  $ means a single scalar value
  @ means an array
  % means a hash

One more preview, foreshadowing a lesson later in this course: the same array can behave completely differently depending on how it's used.

my @array = (10, 20, 30);
my $count = @array;
print "Array: @array\n";
print "Count: $count\n";
Output
Array: 10 20 30
Count: 3

Assigning @array to a scalar $count didn't store a reference or throw an error — it gave $count the number of elements, 3. This is called context, and it has no real equivalent in Python, JavaScript, Rust, Go, or any other language on this site. The context lesson later in this course covers it in depth. Next: your first real program, with use strict and use warnings — the safety rails every real Perl script turns on.

Practice exercise

Declare my $name = "Perl" and my @sigils = ('$', '@', '%'). Print @sigils joined by spaces using join(" ", @sigils), then print $name on its own line.