typestar

Scalars & sigils in Perl

One $ sigil for every single value, whether it holds a string or a number.

use strict;
use warnings;

# one sigil, one value: strings and numbers share the scalar
my $name  = "perl";
my $year  = 1987;
my $ratio = 0.5;

my $port = "8080";
print "$name arrived in $year\n";
print $port + 1, " is one port up\n";
print "half of $year is ", $year * $ratio, "\n";

my $tag = $name . "-" . $year;
print "tag: $tag\n";

How it works

  1. my declares a lexical scalar; use strict makes the declaration mandatory.
  2. Double-quoted strings interpolate $name and $year right in place.
  3. + and * treat the numeric string "8080" as a number; . concatenates.

Keywords and builtins used here

The run, in numbers

Lines
15
Characters to type
336
Tokens
68
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 58 seconds.

Type this snippet

Step 1 of 3 in Scalars & sigils, step 1 of 27 in Language basics.

Next →