Using Variables in Perl

$_, the default variable. Creating containers for variables in Perl is easy. Give the container a name (which is made up of a combination of the letters A-Z, a-z, the digits 0-9 and the underscore character), then precede the name with one of Perl’s special variable naming characters, depending on what the variable will be used for:

$ – a scalar variable (one of something);
@ – an array variable (a collection of somethings, a list);

% – a hash variable (a collection of name/value pairs); and
\ – a referenced variable (a ‘pointer’ to something else, usually another variable).

Comments are closed.