Naming
- Variables are a letter, followed by zero or more letters, digits or
underscores
- Case-sensitive
- All characters are significant
- Sign defines type of variable:
$scalar @list %hash Interpolation
- Strings inside of doublequotes are expanded out
print "There were $nmatches matches
found."; is the same as print "There were ", $nmatches, " matches found.";
- Quoting the dollar sign removes significance:
my $n=5; print "The value of \$n is $n";
gives The value of
$n is 5 Scope
- By default, variables are global.
- local $var hides
& saves a copy of $var for the duration of the block.
- my $var is probably
what you want for "local variables" as we understand them from C and
other languages.
|
|
|