< Perl Tutorial

Perl data types

← Previous Next →

Perl Datatypes

Perl has three basic data types. They are scalars, arrays and hashes. Here are some details about these three datatypes:

  • Scalar - Scalars are simple variables. They are preceded by a dollar sign ($). A scalar is either a number or a string.
  • Arrays - Arrays are ordered lists of scalars that we access with a numeric index, which starts with 0. They are preceded by an "at" sign (@).
  • Hashes - Hashes are unordered sets of key/value pairs that you access using the keys as subscripts. They are preceded by a percent sign (%).

Perl Literals

Perl has two types of literals namely Numeric and String literals.

  • String Literals - Strings are sequences of characters. They are usually alphanumeric values delimited by either single (') or double (") quotes. Double-quoted string literals allow variable interpolation, and single-quoted strings are not. Commonly used Escape Sequences are:

     Escape Sequence Meaning 
     \\  Backslash
     \'  Single Quote
     \"  Double Qoute
     \a  Alert
     \b  Backspace
     \f  Formfeed
     \n  New line
     \r  Carriage Return
     \t  Vertical Tab
  • Numeric Literals - Perl stores all the numbers internally as either signed integers or double-precision floating-point values. Numeric literals are specified in any of the following floating-point or integer formats:

     Type Value 
     Integer  5412
     Negative Integer  -1234
     Floating-point   2.0123
     Scientific Notation  413.E25
     Hexadecimal  0x5212AEF
     Octal  056347



← Previous Next →