in reply to The beauty that is perl.

Can you guess what each is going to print before you run it?

Its unlikely many will that dont already know of this bug. I certainly didn't. And im pretty sure this is a bug and in my eyes not in the slightest bit beautiful. For those that want this spelled out. (Update: actually maybe it isnt a bug, suprising as hell, but not a bug.)

This should be

  1. 'bar'
  2. syntax error. $\ is a legal var name so it should parse as " ' $\ " ' " the last two tokens being a syntax error.
  3. '
    ;'
  4. Similar error to 2.

Instead its 'best' for them all. Very tricky, and IMO a bug. $\; should not parse as $; in a double quoted string. Likewise for $\;

Update: Except that im wrong. The rules are: Find the end, unescape any escaped delimiters, handle interpolation. Thus the $\; becomes $; before the interpolation scan starts, which explains this brain teaser. And IMO is worth a perldoc update just to point it out. ++ to bart and buu.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re: Re: The beauty that is perl.
by ysth (Canon) on Apr 04, 2004 at 13:12 UTC
    One practical consequence of this is that you can't "escape" some delimiters to match literally, e.g.: m$\$$ will treat $ as the end-of-line assertion (or as variable interpolation if $ is followed by an identifier), but there's no way to get it to match '$'.

      But that's ok, as you can still use \x24, or even \N{DOLLAR SIGN} after use charnames ":full";.

      Imo, if you want to match a literal dollar sign in the regexp, you just should not use a dollar sign if you want to match a literal dollar sign. That's the same thing as /^\/usr\/bin\//-like regexps, or even worse.