Constants
TrafficScript allows you to specify integer, boolean, floating point, and string values:
- Integers: sequences of digits, such as “23”; hex format (0xff) and octal format (\377) are also supported.
- Boolean: TrafficScript provides two boolean keyword constants, true and false, for use in comparison expressions. These constants are synonymous with 1 and 0 respectively, and can be used where an explicit truth test or return value is required.
- Floating point: decimal point (3.14) and scientific (5.6e-2) notations are both supported.
- Strings: strings are character sequences, enclosed by double (“) quotes or single (‘) quotes.
In double-quoted strings, special characters can be escaped using the standard backslash “\” notation (for example, “\n” is a newline character), using octal notation (“\012” is also a newline) or using hexadecimal notation (“\x0A” is a newline).
In single-quoted strings, no escaping is performed. For example, “\n” is not converted to the newline character.
In both types of string, for improved readability, strings can be broken across lines using a single “\” followed by a newline:
# The following two lines both create the string ‘Hello world’
$single = 'Hello \
world';
$double = "Hello \
world";Although, in the case of a single quoted string, not specifying the “\” at the end of the line still causes TrafficScript to insert a newline character.
Be aware of escaping rules when writing regular expressions in TrafficScript. For example, in a double-quoted TrafficScript string, the character “\” automatically escapes the next character, so if you want a literal “\” in your string, double-escape it using “\\”. For this reason, regular expressions are often written using single-quoted strings.
