home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!mcsun!sunic!dkuug!iesd!iesd.auc.dk!krab
- From: krab@iesd.auc.dk (Kresten Krab Thorup)
- Subject: Re: Help with quotes
- In-Reply-To: lwall@netlabs.com's message of 6 Nov 92 19:05:30 GMT
- Message-ID: <KRAB.92Nov7181815@falk.iesd.auc.dk>
- Sender: news@iesd.auc.dk (UseNet News)
- Organization: Mathematics and Computer Science, Aalborg University
- References: <FILO.92Nov4211406@pegasus.Stanford.EDU>
- <1992Nov6.190530.20726@netlabs.com>
- Distribution: comp
- Date: 7 Nov 92 18:18:15
- Lines: 50
-
- >>>>> On 6 Nov 92 19:05:30 GMT, lwall@netlabs.com (Larry Wall) said:
- :> Nntp-Posting-Host: scalpel.netlabs.com
-
- :> In article <FILO.92Nov4211406@pegasus.Stanford.EDU> filo@pegasus.stanford.edu writes:
- :> : I'm having a bit of a problem with quoting.
- :> :
- :> : This works as expected. It replaces the first character with a double-
- :> : quote.
- :> :
- :> : $ perl -pe 's/./sprintf ("\\"")/e; print "<$@>" if $@'
- :> : help
- :> : "elp
- :> : $
- :> :
- :> : Below is the same thing except $& has been added to the sprintf. In
- :> : this case the evaluation of the replacement string fails. I have not
- :> : been able to find a way to properly escape the double-quote to be
- :> : printed.
- :> :
- :> : $ perl -pe 's/./sprintf ("$&\\"")/e; print "<$@>" if $@'
- :> : help
- :> : <EOF in string at (eval) line 1, <> line 1.
- :> : >elp
- :> : $
- :> :
- :> : I know I could just changes quote characters, but I need a way to
- :> : include the quote character inside the quoted string.
-
- :> Admittedly it's probably a bug, but changing the inner quote characters
- :> is not your only option. You can also change the outer quote characters,
- :> like this:
-
- :> perl -pe 's/./sprintf(qq!$&"!)/e; print "<$@>" if $@'
-
- :> The whole idea of q and qq is to get away from the necessity of
- :> counting backslashes or parens. (One of the benefits of having More
- :> Than One Way To Do It is that if one of the ways doesn't work out, you
- :> can do it a different way, no?)
-
- The problem may be, that you're using bash (the prompt $) could look
- like you do :-) Bash has a lot of troubles expanding quotes right....
-
- /Kresten
- --
- Kresten Krab Thorup, DAT3, D2-117 | / | E-mail : krab@iesd.auc.dk
- Institute of Electronic Systems | ,-'/( | S-mail : Sigrid Undsetsvej 234A
- Aalborg University | / | \ | 9220 Aalborg \O
- Fr. Bajers vej 7, 9220 Aalb. \O | A U C | 98 15 18 44
- -------------------------------------------------------------------------------
- Member of the LPF - The League for Programming Freedom
-