develooper Front page | | Postings from September 2000

Re: RFC 328 (v1) Single quotes don't interpolate \' and \\

Thread Previous | Thread Next
Hildo Biersma
September 30, 2000 02:00
Re: RFC 328 (v1) Single quotes don't interpolate \' and \\
Message ID:
Nicholas Clark wrote:

> What do you mean by "need"? Strings need to be able to contain single
> quotes, but single quotes are not the only way to build a string. Single
> and double quotes don't generate a different fundamental type; a double
> quoted string with no variable interpolation also generates a string
> constant.  Having an escape system for single quotes makes it easy to
> embed a ' inside a string without worrying about what else would mean
> something special to double quote interpolation. But makes it necessary
> to remember the escape system, which does differ from the "" system.

Well, duh.  The reason signle-quoted strings are there in the first
place is to create strings free from interpolation, without the need to
escape every $, @, \n, \t, etc.  And if you want to do that, you also
need to include single quotes.

This issue does not exist in languages that don't do interpolation, e.g.
C and C++, and there the single quote indicates a character type.  Not
something we'd want in perl.

> I'm proposing *no* escape character. Not a different escape character,
> but a lack of escape character. It doesn't change how strings are
> stored internally, just how the language parser sees one particular
> construction that generates a string.

Thus making it harder to create non-interpolated but still
general-purpose strings.

> They are required to build a string from single quotes. But I can write the
> above as
> $line = "This string contains both single \' and double \" quotes';
> $line = "This single-quoted string ends on a backlash \\";

So what?  As soon as any of the other special characters and sequences
come up ($, @, \n, \t, etc) this starts to suck deeply.

> The precise behaviour of backslash in single quote string syntax in perl is
> unique to perl. Double quote backslash behaviour is very close to C,
> double quote interpolation behaviour is close to unix shells.

It may be unique to perl (and I'm not sure it is), but is it a
consistent escape mechanism.  The SQL / BASIC approach listed below is
awful, as it would require you to learn two different kinds of escape

> An alternative to either of the above could be to borrow SQL or BASIC's
> syntax:
> $line = 'This string contains both single '' and double " quotes';
> $line = 'This single-quoted string ends on a backslash \';
> but I don't think that this is a good idea.


Now, I have been teaching perl for a number of years, and nobody's ever
had trouble with understanding how single quotes and the two escapes
work.  Plenty of people find double-quotes either too powerful or too
limited (see the various RFCs), but I think single quotes are fine.

Ah well, we'll see.  Note me down as disagreeing with your RFC...


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About