home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6859 < prev    next >
Encoding:
Internet Message Format  |  1992-11-04  |  1.1 KB

  1. Path: sparky!uunet!olivea!spool.mu.edu!agate!stanford.edu!leland.Stanford.EDU!leland!filo
  2. From: filo@pegasus.Stanford.EDU (David Filo)
  3. Newsgroups: comp.lang.perl
  4. Subject: Help with quotes
  5. Message-ID: <FILO.92Nov4211406@pegasus.Stanford.EDU>
  6. Date: 5 Nov 92 05:14:06 GMT
  7. Sender: news@leland.Stanford.EDU (Mr News)
  8. Reply-To: filo@pegasus.stanford.edu
  9. Distribution: comp
  10. Organization: Stanford University
  11. Lines: 30
  12.  
  13. I'm having a bit of a problem with quoting.
  14.  
  15. This works as expected.  It replaces the first character with a double-
  16. quote.
  17.  
  18. $ perl -pe 's/./sprintf ("\\"")/e; print "<$@>" if $@'
  19. help
  20. "elp
  21. $
  22.  
  23. Below is the same thing except $& has been added to the sprintf.  In
  24. this case the evaluation of the replacement string fails.  I have not
  25. been able to find a way to properly escape the double-quote to be
  26. printed.
  27.  
  28. $ perl -pe 's/./sprintf ("$&\\"")/e; print "<$@>" if $@'
  29. help
  30. <EOF in string at (eval) line 1, <> line 1.
  31. >elp
  32. $
  33.  
  34. I know I could just changes quote characters, but I need a way to
  35. include the quote character inside the quoted string.
  36.  
  37. Any help on this would be greatly appreciated.
  38.  
  39. Thanks,
  40.  
  41. David Filo
  42. filo@pegasus.stanford.edu
  43.