Online Learning Applications for Technical English


Home
Syllabus
Assignments

Instructor



Producing Homepages

Values in Perl are: 1) numbers, 2) strings, or 3) undef.

  1. Numbers can use: decimal points, plus or minus signs, and power-of-ten indicators. For example:

      0
      2002
      -40
      255
      61298040283768
      1.25
      255.000
      255.0
      7.25e45           # 7.25 times 10 to the 45th power
      -6.5e24           # negative 6.5 times 10 to the 24th power
      -12e-24           # negative 12 times 10 to the -24th power
      -1.2E-23          # same as above (uppercase E is OK)
    
    For non-decimal representation, we use a leading 0 for octal (base 8), leading 0x for hexadecimal (base 16), and a leading 0b for binary:
      0377              # 377 octal, same as 255 decimal
      0xFF              # FF hex, also 255 decimal
      0b11111111        # also 255 decimal
    
  2. Strings are sequences of characters. Inside single quotes, they are exactly the characters printed. To put a single quote inside a string, use a leading backslash. To include a backslash character before a single quote, use two backslashes. For example,
      'abc'             # three characters: a, b, and c
      ''                # the null string (no characters)
      'There\'s a single quote character inside single quotes'
      'The last character is a backslash: \\'
      'hello\n'         # hello followed by backslash followed by n
      'hello
      there'            # hello, newline, there (11 characters)
    

    Inside double quotes, the backslash is used to specify control characters.

      "abc"                 # same as 'abc'
      "Hello, world!\n"     # Hello, world! and a newline
      "The last character is a double quote mark: \""
    
  3. undef is the value of variables before they are first assigned. It acts like a 0 or empty string.

To make a list of values, we use comma delimiters between parentheses:

  (1, 2, 3)        # list of three values: 1, 2, and 3
  ("abc", 4.5)     # two values:  "abc" and 4.5
  ()               # empty list
  (1..100)         # list of 100 integers

[ Back ]