Understanding Scalar Values
A Scalar Value is one unit of data, the data can either by a number or a chunk of text. All scalar variable have an initial value of the null string if not assigned, this means that you do not need to define.
In scalar values, a value that was assigned as a string can be used as a integer whenever it makes sense to do so and vice versa.
Scalar Values |
|
Integer | Can contain one or more digits, optionally proceeded by either a plus or minus sign and optionally containing underscores. There is a limit of how many digits can be contained in the number, this depends on the type of machine you use. To use octal number you start the number with a 0 (zero) |
Floating-Point | A floating point number consists of the following
The exponent represent the value by which to multiply or divide the scalar value by a power of ten. the exponent e+01 means multiply by ten, e+02 means multiply by 100 and e+03 means multiply by 1000, etc. The exponent e-01 means divide by ten, e-02 means divide by 100 and so on. Remember that round-off will occur when perl meets it maximum limit, this depend on what machine you use. |
Octal and Hexadecimal | Perl also enables you to use two other notations to represent integer scalar values
|
Character Strings | A character string is a sequence of one or more letters, digits, spaces or special characters. When you assign a string variable you can either use double quotes (variable substitution) or single quotes (no substitution). Variable substitution means that when Perl sees a variable ( starts with a dollar sign($) ) inside the double quotes it knows that this is a variable and substitutes it for the variable's value. There are lots of escapes sequences for character strings and need to be in double quotes to work, see Perl Cheat sheet for more details |
Scalar Value Examples |
|
Integer | $salary = 10000; |
Floating-Point | $mars_bar = 0.50; $a_large_number = 1.2e+05; # remember that e+05 means multiply by 100000 |
Octal and Hexadecimal | $result = 047; # this assign octal 47 or decimal 39 ( notice the leading 0 (zero) ) $result = 0x1f; # this assign hexadecimal 1F or decimal 31 ( notice the leading 0x) |
Character Strings | $string = "Hello World"; ## Using escape sequences ## Using a string as a integer |