in reply to \ in single quotes (Re: DOS directory naming in PERL?)
in thread DOS directory naming in PERL?

tye, you may disagree with this decision, but that doesn't make it a mistake. That is why I used the word 'decision'.

The biggest flaw with your suggestion is that changing the quoting character means scanning the string to make two changes instead of one; the previous delimiter must be made single everywhere it is double, and the new delimiter must be made double everywhere it is single. Miss fixing the original delimiter in one case, and you've changed your string, with no hint that it was ever different.

On the other hand, with backslashing, the backslashes don't need to be removed from the old delimiter. In fact, Perl's documentation explicitly state that in a double-quoted string, a backslashed non-word character always means the literal character. You never have to worry about how the string should be interpreted, unlike your scheme where ** could mean one asterisk or two, depending on the delimiters used.

Both approaches have advantages and disadvantages, and both are used in a lot of places. I don't think it's obvious that one solution is necessarily better than the other.

  • Comment on Re: \ in single quotes (Re: DOS directory naming in PERL?)

Replies are listed 'Best First'.
(tye)Re: \ in single quotes (Re: DOS directory naming in PERL?)
by tye (Sage) on Jan 22, 2001 at 09:29 UTC

    The biggest flaw with your suggestion is that changing the quoting character means scanning the string to make two changes instead of one; the previous delimiter must be made single everywhere it is double, and the new delimiter must be made double everywhere it is single.

    Ah, and this is different in the current scheme, how? (:

    q'The string\'s "old" delimiter isn\'t new' # Change the delimiter from ' to " and... q"The string's \"old\" delimiter isn't new" # we have to change _both_ old and new delims, cuz... q"The string\'s \"old\" delimiter isn\'t new" # would end up including \s in front of the old delims...

    In fact, Perl's documentation explicitly state that in a double-quoted string, a backslashed non-word character always means the literal character.

    ...because we aren't talking about double-quoted strings but single-quoted strings.

    So if this is the biggest flaw with my proposal, I still assert that it would be a better choice to go along with the other quoting methods provided in Perl.

            - tye (but my friends call me "Tye")