[TxMt] Bug in perl syntax?

Allan Odgaard throw-away-1 at macromates.com
Thu Feb 15 17:46:57 UTC 2007


On 15. Feb 2007, at 18:01, Grant Hollingworth wrote:

> * Allan Odgaard <throw-away-1 at macromates.com> [2007-02-14 21:37]:
>> I assume variables are allowed in regexps?
>>
>> So likely Perl distinguish between end-of-line-$ and start-of-  
>> variable-$ by what follows the character? We could make the  
>> regexp  variable rule do the same in TM.
>
> Right.  The problem is that Perl allows almost any punctuation  
> character to be a regexp delimiter.  For paired delimiters we  
> specify the end character explicitly:
> [...]
> Here, the variable pattern seems to have precedence over \2.

Actually not, i.e. the following works fine:

    my $foo = qr$allan$;

What fails is using $ in a regexp where it looks like a variable but  
is actually not.

Normally in Perl $/ is a predefined variable, which means we can do  
the following (which TextMate handles correctly, and Perl as well :) ):

    my $foo = qr!test $/!;

But now let’s use / as delimiter instead:

    my $foo = qr/test $//;

This is ambiguous. TextMate chooses to still see $/ as the predefined  
variable, and thus considers the entire line as well-formed, where  
Perl switches interpretation of $ into the end-of-line anchor, which  
makes it choke at the last / (since the second last / terminates the  
regexp).




More information about the textmate mailing list