- my
- scalar variables
Scalar variables (use my)
- Scalar variables always start with a $ sign, name is alphanumeric (a-zA-Z0-9) and underscore (_)
- A scalar variable can hold a string, a number, a reference to another data-structure, undef
- Value assignment to variable 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
examples/scalars/scalar_variables.pl
#!/usr/bin/perl use strict; use warnings; my $greeting = "Hello world\n"; my $the_answer = 42; my $name; # undef print $greeting; print $the_answer, "\n"; $name = 'Foo Bar'; print $name, "\n"; $the_answer = "Hi, you two";
The value can be changed any time.