[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] bug?



On Sat, 26 Jul 1997 15:14:54 -0500 Chris Nandor wrote:

>Can anyone confirm whether or not this is correct behavior?
>        print q{\{this # and that\}}
>I would expect this to print:
>        {this # and that}
>But it prints:
>        \{this # and that}
>And ...
>        print q{{this # and that\}}
>returns:
>        # Can't find string terminator "}" anywhere before EOF.

>This to me seems like a bug.  I can understand treating { specially
>throughout, but then it should be able to be escaped, as ' would.

How interesting: it is exactly as you say. But I think it is not to do with
the '{' and '}' characters as such, since:

        print q{\{\}}, "\n";  #prints \{}
and     print q[\[\]], "\n";  #prints \[]

q[\[]] gives rise to an "unmatched right bracket" error and q[[\]] (as you
say) a "can't find string terminator" error. The nub of the problem seems
to be that Perl interpolates an escaped closing bracket (which it shouldn't
in a single quoted string) but not an escaped forward bracket, i.e.

       print [\]] -> ]
but    print [\[] -> \[

However if the character used as the 'quote alias' is _different_ from the
character escaped inside the quote, behaviour is as expected, e.g.:

        print q{\[\]}, "\n";  #prints \[\]
        print q[\{\}], "\n";  #prints \{\}

Perl seems to get confused with single quotes but oddly not with double quotes:

        print qq[\[\]], "\n"; #prints []
        print qq{\{\}}, "\n"; #prints {}

The nearest thing in Programming Perl seems to be on pp 41/42: "Pick your
own quotes", where it states that "Embedded occurrences of delimiters must
match in pairs" -- meaning a matched pair of "" for example inside a qq()
-- which is not quite the same thing. I cnnot find any warnings against
using the 'quote alias' character (escaped or not) inside single quotes.

>I further confirmed the problem in perl5.00401, so unless I hear there is a
>good reason for this, I'll report it to perlbug.

It is a very nasty trap for the unwary to be sure, and many thanks for
pointing it out. It will be interesting to hear what 'perlbug' has to say
about it.

Alan Fry



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch