Scalars are simple variables that are either numbers or strings of characters. Scalar variable names begin with a dollar sign followed by a letter, then possibly more letters, digits, or underscores. Variable names are case-sensitive.
Numbers are represented internally as either signed integers or double precision floating point numbers. Floating point literals are the same used in C. Integer literals include decimal (255), octal (0377), and hexadecimal (0xff) values.
Strings are simply sequences of characters. String literals are delimited by quotes:
|Single quote||‘string’||Enclose a sequence of characters|
|Double quote||“string”||Subject to backslash and variable interpolation|
|Back quote||`command`||Evaluates to the output of the enclosed command|
The backslash escapes are the same as those used in C:
|\n Newline||\e Escape|
|\r Carriage return||\\ Backslash|
|\t Tab||\” Double quote|
|\b Backspace||\’ Single quote|
In Windows, to represent a path, use either “c:\\temp” (an escaped backslash) or “c:/temp” (UNIX-style forward slash).
Strings can be concatenated using the “.” operator:
The easiest means to get operator input to your program is using the “diamond” operator:
The input from the diamond operator includes a newline (\n). To get rid of this pesky character, use either chop() or chomp(). chop() removes the last character of the string, while chomp() removes any line-ending characters (defined in the special variable $/). If no argument is given, these functions operate on the $_ variable.
To do the converse, simply use Perl’s print function: