Scalar variables always start with a $ sign, name is alphanumeric (a-zA-Z0-9) and underscore (_)
A scalar variable can hold either a string or a number
Value assignment to varaible is done by the = sign
Use the my keyword to declare variables (optional but recommended)
$this_is_a_long_scalar_variable $ThisIsAlsoGoodButWeUseItLessInPerl $h $H # $h and $H are two different variables
Example 5-1. examples/scalars/scalar_variables.pl
#!/usr/bin/perl use strict; use warnings; my $greeting = "Hello world\n"; my $the_answer = 42; print $greeting; print $the_answer, "\n";
A scalar can hold either string or numerical value. They can be changed any
time. If a value was not given it holds the special value 'undef'.
my $x; # the value is a special value called 'undef'
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Scalars | Up | Greeting with a name, Variable interpolation |