home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6896 < prev    next >
Encoding:
Text File  |  1992-11-08  |  2.5 KB  |  65 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!mcsun!sunic!dkuug!iesd!iesd.auc.dk!krab
  3. From: krab@iesd.auc.dk (Kresten Krab Thorup)
  4. Subject: Re: Help with quotes
  5. In-Reply-To: lwall@netlabs.com's message of 6 Nov 92 19:05:30 GMT
  6. Message-ID: <KRAB.92Nov7181815@falk.iesd.auc.dk>
  7. Sender: news@iesd.auc.dk (UseNet News)
  8. Organization: Mathematics and Computer Science, Aalborg University
  9. References: <FILO.92Nov4211406@pegasus.Stanford.EDU>
  10.     <1992Nov6.190530.20726@netlabs.com>
  11. Distribution: comp
  12. Date: 7 Nov 92 18:18:15
  13. Lines: 50
  14.  
  15. >>>>> On 6 Nov 92 19:05:30 GMT, lwall@netlabs.com (Larry Wall) said:
  16. :> Nntp-Posting-Host: scalpel.netlabs.com
  17.  
  18. :> In article <FILO.92Nov4211406@pegasus.Stanford.EDU> filo@pegasus.stanford.edu writes:
  19. :> : I'm having a bit of a problem with quoting.
  20. :> : 
  21. :> : This works as expected.  It replaces the first character with a double-
  22. :> : quote.
  23. :> : 
  24. :> : $ perl -pe 's/./sprintf ("\\"")/e; print "<$@>" if $@'
  25. :> : help
  26. :> : "elp
  27. :> : $
  28. :> : 
  29. :> : Below is the same thing except $& has been added to the sprintf.  In
  30. :> : this case the evaluation of the replacement string fails.  I have not
  31. :> : been able to find a way to properly escape the double-quote to be
  32. :> : printed.
  33. :> : 
  34. :> : $ perl -pe 's/./sprintf ("$&\\"")/e; print "<$@>" if $@'
  35. :> : help
  36. :> : <EOF in string at (eval) line 1, <> line 1.
  37. :> : >elp
  38. :> : $
  39. :> : 
  40. :> : I know I could just changes quote characters, but I need a way to
  41. :> : include the quote character inside the quoted string.
  42.  
  43. :> Admittedly it's probably a bug, but changing the inner quote characters
  44. :> is not your only option.  You can also change the outer quote characters,
  45. :> like this:
  46.  
  47. :>     perl -pe 's/./sprintf(qq!$&"!)/e; print "<$@>" if $@'
  48.  
  49. :> The whole idea of q and qq is to get away from the necessity of
  50. :> counting backslashes or parens.  (One of the benefits of having More
  51. :> Than One Way To Do It is that if one of the ways doesn't work out, you
  52. :> can do it a different way, no?)
  53.  
  54. The problem may be, that you're using bash (the prompt $) could look
  55. like you do :-)  Bash has a lot of troubles expanding quotes right....
  56.  
  57. /Kresten
  58. --
  59. Kresten Krab Thorup, DAT3, D2-117 |       /   | E-mail : krab@iesd.auc.dk
  60. Institute of Electronic Systems   |   ,-'/(   | S-mail : Sigrid Undsetsvej 234A
  61. Aalborg University                |  /  |  \  |          9220 Aalborg \O
  62. Fr. Bajers vej 7, 9220 Aalb. \O   |  A  U  C  |          98 15 18 44
  63. -------------------------------------------------------------------------------
  64.            Member of the LPF - The League for Programming Freedom
  65.