Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Single Quotes - how to avoid any escape processing?

by LanX (Bishop)
on Jan 31, 2013 at 21:59 UTC ( #1016402=note: print w/replies, xml ) Need Help??

in reply to Re^2: Single Quotes - how to avoid any escape processing?
in thread Single Quotes - how to avoid any escape processing?

> But why is this always considered a necessary feature for a quoting delimiter, trumping all other considerations like avoiding headaches like the OP describes?

I didn't say it's a necessary, I explained the motivation "If ... you want to allow ...".

> What would prevent the usage of the delimiting character as its own escape character? I.e. two consecutive single-quotes would not terminate a single-quoted string literal

IIRC VB (or VB-Script) does something like this.

> I don't see any reason for ever wanting to put two string literals right next to each other without space or comma in between, so it would not create any syntactical ambiguity.

empty string?

> Or am I missing something?

Perl has already a very complex syntax, adding new extra DWIM exception doesn't make it easier.

What might be easy and meaningful for you can be line noise or just complexity horror for someone else.

For instance see this discussion about the differences between Perl and JS in handling the closing bracket in regex-character classes: Regex: Char-class equivalent for [^].

So in short: Rules have to be kept as simple as possible and backslashing is a well-established notation.

Moritz already mentioned a new way in Perl6, which sounds reasonably simple, so help is on the way for the next version.

EDIT: And for the records: The OP might hate them but I LOVE HERE-DOCS!!!

Cheers Rolf

  • Comment on Re^3: Single Quotes - how to avoid any escape processing?

Replies are listed 'Best First'.
Re^4: Single Quotes - how to avoid any escape processing?
by smls (Friar) on Jan 31, 2013 at 22:57 UTC

    > empty string?

    I don't think that would create a problem, since the search for the end delimiter would begin right after the start delimiter, not including it.
    The regex for matching such a single-quoted string would effectively be:
    ...which would match the empty string case just fine.

    > What's easy for you might be the horror for someone else.

    Well, one way to compare & contrast DWIM "horrors" would be to consider the likelihood of unsuspecting users "falling into the trap" while just going about their normal routine programming.

    Many who learn Perl come to colloquially know single-quoted strings as "like normal strings, but without escaping and interpolating". Then they go about using them, with perfect results, until at some point they are bitten by weird bugs like the OP described.
    While writing something like
      $path = '\\aaa\bbb';
    a non-experienced user who knows single-quoted strings as "strings without escaping", won't even consider that the double-slashes might cause unintended behavior.

    One the other hand, the same user would probably not write something like
      $contraction = 'Don''t';
    unless they were consciously experimenting how single-quoted strings behave in special cases. It would raise a red flag, because it challenges what they know about how start and end delimiters for string literals work.

    In both cases, people will not know how exactly things work until they are taught.
    But in the second case, they will know about not knowing something when it matters, whereas in the first case it will catch them by surprise later in the form of bugs.

Re^4: Single Quotes - how to avoid any escape processing?
by temporal (Pilgrim) on Jan 31, 2013 at 22:55 UTC

    Love... here-docs?!
    You must explain your reasoning behind this calculated insanity!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016402]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-06-24 10:16 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.