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
machanisms.
>
> 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.
Indeed.
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...
Hildo