Free preview.You're sampling one lesson — enroll free to unlock all 7 lessons and track your progress.
Enroll free lesson
Variables and Logic
Variables and Logic
In this lesson — part of Scripting Basics — you'll learn variables and logic in Perl and why it matters in real work.
Why it matters
Variables are how programs remember values — the foundation of every computation.
Key ideas
- A variable is a name bound to a value
- Choose clear, descriptive names
- Constants vs. reassignable variables
- Values have types
In practice
Here's how it looks in idiomatic Perl:
use strict;
use warnings;
# Three sigils select the variable kind, not the data type
my $count = 42; # scalar: one value
my @list = (1, 2, 3); # array: ordered list
my %map = (red => 1); # hash: key/value pairs
my $ref = \@list; # take a reference (a scalar)
our $GLOBAL = 'pkg-var'; # package global, not lexical
print "$count @list $ref->[0]\n";
Perl note: The sigil ($, @, %) denotes how you're ACCESSING the container, not a fixed type, so $list[0] (scalar access) and @list (list access) refer to the same array.
Try it yourself
Exercise: Declare three variables in Perl (a name, an age, and whether you're learning) and print them.
Recap
You now understand variables and logic and can apply it in Perl. Mark this lesson complete and continue to the next one.
