Assigning a value
= operator to put a new value into a scalar container.
my $name; $name = 'Anna';
You can now use the variable and, for example, print it:
Multiple variables can be assigned at once. For example, this is how to assign two scalars in a single statement:
my ($a, $b); ($a, $b) = 10, 20;
Notice that you cannot omit the parentheses on the left-hand side. But you can add them for symmetry on the right side:
($a, $b) = (10, 20);
Complete the quizzes that cover the contents of this topic.
💪 Or jump directly to the exercises to this section.