Lesson 2 of 15

Scalar Variables

Scalar Variables

In Perl, scalar variables hold a single value -- a number, a string, or a reference. They are prefixed with $:

my $name = "Alice";
my $age = 30;
my $pi = 3.14159;

The my keyword declares a new variable with lexical scope.

Numbers

Perl handles integers and floating-point numbers seamlessly:

my $x = 10;
my $y = 3.5;
my $z = $x + $y;   # 13.5

Strings

Strings can be single-quoted (literal) or double-quoted (with interpolation):

my $greeting = 'Hello';        # no interpolation
my $message = "Hi, $name!";   # interpolates $name

Your Task

Declare a variable $language set to "Perl" and print I am learning Perl using string interpolation.

JS Transpiler loading...
Loading...
Click "Run" to execute your code.