Skip to Main Content
Perl for Web Site Management
book

Perl for Web Site Management

by John Callender
October 2001
Beginner content levelBeginner
528 pages
15h 20m
English
O'Reilly Media, Inc.
Content preview from Perl for Web Site Management

A Bit More About Quoting

So far, whenever we’ve needed to quote a string we’ve used double quotes (as in, "this is a double-quoted string"). In fact, Perl also supports the use of single quotes (as in, 'this is a single-quoted string'). It’s important for you to understand the difference between the two.

The difference is just this: when it processes a double-quoted string, Perl looks in it for things that look like variables and replaces them with the contents of those variables. This process is called variable interpolation . It also looks for certain sequences beginning with a backslash (\) and replaces them with special characters. The sequences are called backslash escapes, and the process of replacing them with special characters is called backslash interpretation.

When it’s processing a single-quoted string Perl doesn’t bother doing this. You get the string, just like it’s written. (Actually, Perl processes two backslash escapes within a single-quoted string: \', which it interprets as a literal single quote, and \\, which it interprets as a literal backslash. This lets you put literal single quotes and literal backslashes inside your string, which would otherwise be difficult to do.)

Let’s create a new script called quotes.plx (Example 2-2) to see how this works.

Example 2-2. A script to test how Perl treats single- and double-quoted strings

#!/usr/bin/perl # quotes.plx -- test handling of single- and double-quoted strings $veggies = 'rutabagas'; print "I like to eat ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Web Client Programming with Perl

Web Client Programming with Perl

Clinton Wong
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

Ken Williams, Dave Rolsky

Publisher Resources

ISBN: 1565926471Catalog PageErrata