Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by smls (Friar)
on Jan 31, 2013 at 22:57 UTC ( #1016413=note: print w/ replies, xml ) Need Help??


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

> 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.


Comment on Re^4: Single Quotes - how to avoid any escape processing?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016413]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-08-29 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (276 votes), past polls