Deutsch English Français Italiano |
<66f114a9d20bf03cfb305a04d807da6492511772@i2pn2.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: Retro Guy <retroguy@novabbs.com> Newsgroups: misc.test,comp.lang.misc Subject: Re: perl test Date: Sat, 7 Sep 2024 05:07:13 -0700 Organization: i2pn2 (i2pn.org) Message-ID: <66f114a9d20bf03cfb305a04d807da6492511772@i2pn2.org> References: <7e8b459c7297ad24dde92aa1fd073b21@www.novabbs.com> <877cbx4orz.fsf@tilde.institute> <51e8c77eaba5ea4084d0a234a71a4f2e@www.novabbs.com> <vbdoi9$m19l$1@dont-email.me> <7e23f0180a430b8429af2514ba56463b@www.novabbs.org> <vbgflq$15f5c$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Injection-Date: Sat, 7 Sep 2024 12:07:13 -0000 (UTC) Injection-Info: i2pn2.org; logging-data="1175803"; mail-complaints-to="usenet@i2pn2.org"; posting-account="Gg8gAsZLN5FnWZrpbmz42d6ib2C2ewfwYI9Q557pxrY"; User-Agent: 40tude_Dialog/2.0.15.41 X-Spam-Checker-Version: SpamAssassin 4.0.0 Bytes: 2356 Lines: 37 On Sat, 7 Sep 2024 03:01:14 -0000 (UTC), Peter Dean wrote: > In comp.lang.misc Retro Guy <retroguy@novabbs.com> wrote: >> On Fri, 6 Sep 2024 2:14:33 +0000, Lawrence D'Oliveiro wrote: >> >>> On Sat, 31 Aug 2024 12:33:39 +0000, Retro Guy wrote: >>> >>>> I figured out my Perl issue. =~ s/([\"])/\\$1/g; does the trick. >>> >>> If that Perl code does what I think it does, the following Python >>> equivalent is simpler: >>> >>> «str-expr».replace('"', '""') >> >> The Perl code above escapes quotes, so adds '\' before any " >> >> I know nothing of Python :) >> >> I actually ended up with =~ s/([\$"])/\\$1/g; in my final code. I needed >> to escape both quotes and '$' >> > > would it hurt to backslash everything nonalphanumeric? > > perldoc -f quotemeta My use case was escaping a set of strings for use in a command line. Something like: $arguments = '"' . $tempfile . '" "' . $name . '" "' . $something . '"'; $returnvalue = `/usr/bin/php /path/to/program.php $arguments`; I needed to escape " and $, but anything else and the '\' would remain, causing the value of the string to be incorrect when used at the target. There's probably a better way in Perl than what I did, but I don't know much about Perl. I do understand regex reasonably well, but not Perl as a language.