Perl language is a loosely typed language, the Perl interpreter itself chooses the data type. Hence, there is no need to specify data type in Perl programming.
There are basically three data types in Perl:
In Perl there are two different types of scalar constants:
Perl numeric literals are numbers. Perl stores number internally as either signed integers or floating-point values.
Perl numeric literals can be assigned following types of formats:
Number | Type |
---|---|
526 | Integer |
5.5 | Floating point |
5e10 | Scientific notation |
5.5E | Scientific notation |
5_549_63 | A large number |
010101 | Binary number |
0175 | Octal number |
AF0230 | Hexadecimal number |
Look at the above table,
Perl string literals contain an empty string, ASCII text, ASCII with high bits or binary data. There is no limit in a string to contain data. They are surrounded by either a single quote (′) or double quote (″).
Variable interpolation is allowed in double quote string but not in single quote string. Also special characters preceding with backslash (\) are supported by double quote strings only.
Escape Characters in string literals
Characters | Purpose |
---|---|
\n | Denotes newline |
\r | Denotes carriage return |
\ t | Denotes horizontal tab |
\v | Denotes vertical tab |
\Q | Backslash following all non-alphanumeric character |
\a | Denotes alert |
\f | Denotes form feed |
\b | Denotes backspace |
\u | Change next character to uppercase |
\U | change all following characters to uppercase |
\l | Change next character to lowercase |
\L | Change all following character to lowercase |
\E | Denotes \U, \L, \Q |
\cX | Controls characters, X is a variable |
\0nn | Create octal formatted numbers |
\xnn | Create hexadecimal formatted numbers |
\\ | Denote backslash |
\' | Denote single quote |
\" | Denote double quote |