Strings

Strings are sequences of characters (like hello). Each character is an 8-bit value from the entire 256-character set (there’s nothing special about the NUL character, as in some languages).

The shortest possible string has no characters. The longest string fills all of your available memory (although you wouldn’t be able to do much with that). This is in accordance with the principle of “no built-in limits” that Perl follows at every opportunity. Typical strings are printable sequences of letters, digits, and punctuation in the ASCII 32 to ASCII 126 range. However, the ability to have any character from to 255 in a string means that you can create, scan, and manipulate raw binary data as strings—a task with which most other utilities would have great difficulty. (For example, you can patch your operating system by reading it into a Perl string, making the change, and writing the result back out.)

Like numbers, strings have a literal representation (the way you represent the string in a Perl program). Literal strings come in two different flavors: single-quoted strings and double-quoted strings. [26] Another form that looks rather like these two is the back-quoted string (`like this`). This form isn’t so much a literal string as a way to run external commands and get back their output. This form is covered in Chapter 14.

Single-Quoted Strings

A single-quoted string is a sequence of characters enclosed in single quotes. The single quotes are not part of the string itself; ...

Get Learning Perl on Win32 Systems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.