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



In reply to Re: The beauty that is perl. by demerphq
in thread The beauty that is perl. by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.