Variables and Arrays
Perl's variables fall into three major types: scalars, arrays, and associative arrays or hashes.
Perl differentiates variable names based on the first character $, @, or % respectively.
Syntax Meaning
NAME File handle or directory handle
$NAME Scalar variable.
@NAME Array indexed by position number.
%NAME Associative array, also called hash, indexed by string.
NAME() Invoke the subroutine NAME.
&NAME Invoke the subroutine NAME.
*NAME Everything named NAME.
Scalar variables hold a single value, either a text string or a number.
You can set the same variable to hold either text or numeric data, and you can switch by setting a string variable to hold a number, and vice versa.
Related examples in the same category