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
mydeclares a lexical scalar;use strictmakes the declaration mandatory.- Double-quoted strings interpolate
$nameand$yearright in place. +and*treat the numeric string"8080"as a number;.concatenates.
Keywords and builtins used here
myprintuse
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.
Step 1 of 3 in Scalars & sigils, step 1 of 27 in Language basics.