There's a pretty good explanation of it here: 
http://en.wikibooks.org/wiki/Perl_Programming/Strings

Specifically this part:


  *   The sequence \' yields the character ' in the actual string. (This is the 
exception we already discussed above).
  *   The sequence \\ yields the character \ in the actual string. In other 
words, two backslashes right next to each other actually yield only one 
backslash.
  *   A backslash, by itself, cannot be placed at the end of a the 
single-quoted string. This cannot happen because Perl will think that you are 
using the \ to escape the closing '.
The following examples exemplify the various exceptions, and use them properly:
  'I don\'t think so.';          # Note the ' inside is escaped with \
  'Need a \\ (backslash) or \?'; # The \\ gives us \, as does \
  'You can do this: \\';         # A single backslash at the end
  'Three \\\'s: "\\\\\"';        # There are three \ chars between ""
In the last example, note that the resulting string is Three \'s: "\\\". If you 
can follow that example, you have definitely mastered how single-quoted strings 
work!
Instead of unreadable backslash escapes, Perl offers other 
ways<http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators> of 
quoting strings. The first example above could be written as:
  q{I don't think so};            # No \ needed to escape the '


From: perl-win32-users-boun...@listserv.activestate.com 
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Greg 
Aiken
Sent: Wednesday, October 20, 2010 10:10 AM
To: perl-win32-users@listserv.activestate.com
Subject: lame question "\\\\.\\pipe\\pipename" vs '\\.\pipe\pipename'

forgive my ignorance here, but I thought single quoted, or apostrophized 
[however you call this character] (') text strings were supposed to be 
interpreted by perl in an unaltered manner.

sample code, indicating how to reference a named pipe in the Win32::Pipe 
module, shows something like this...

"\\\\.\\pipe\\pipename<file:///\\pipe\pipename>" (note enclosed in quotes)

I thought the excessive quantities of backslashes seemed silly, so I instead 
used single quotes and tried...

'\\.\pipe\pipename' (note enclosed in apostrophies)

only to find that my client pipe program did not work.

I then did a simple test print program;
print '\\.\pipe\pipename';

and I was surprised to see what actually printed to the screen was instead;
\.\pipe\pipename (note the first \ is not shown in output!)

this explained why my client pipe program was working...

but it left me scratching my head to ask, "why is the backslash character being 
interpreted as a special perl operator when it is found within apostrophies?"

I thought that only happened when the backslash is found within quotes, such as 
(print "\x43"), which should print a capital C

thanks in advance to anyone who can explain this to me.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to