Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Do not sleep in a eucalyptus tree tonight.


comp / comp.lang.misc / Re: perl test

SubjectAuthor
* Re: perl testLawrence D'Oliveiro
`* Re: perl testRetro Guy
 +* Re: perl testLawrence D'Oliveiro
 |`* Re: perl testRetro Guy
 | `- Re: perl testLawrence D'Oliveiro
 `* Re: perl testPeter Dean
  +* Re: perl testLawrence D'Oliveiro
  |`* Re: perl testPeter Dean
  | `- Re: perl testPeter Dean
  `* Re: perl testRetro Guy
   +- Re: perl testPeter Dean
   `* Re: perl testLawrence D'Oliveiro
    `* Re: perl testRetro Guy
     `* Re: perl testLawrence D'Oliveiro
      `- Re: perl testRetro Guy

1
Subject: Re: perl test
From: Lawrence D'Oliv
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Fri, 6 Sep 2024 02:14 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Fri, 6 Sep 2024 02:14:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <vbdoi9$m19l$1@dont-email.me>
References: <7e8b459c7297ad24dde92aa1fd073b21@www.novabbs.com>
<877cbx4orz.fsf@tilde.institute>
<51e8c77eaba5ea4084d0a234a71a4f2e@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 06 Sep 2024 04:14:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="52cdf5b83a21d9c99d3753754a9933f5";
logging-data="722229"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+diRXf4EwdywJ7BoM3JxHZ"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:EZmUG7FdXL/ZGpgC91zjQ7yuMYI=
View all headers

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('"', '""')

Subject: Re: perl test
From: Retro Guy
Newsgroups: misc.test, comp.lang.misc
Organization: Rocksolid Light
Date: Fri, 6 Sep 2024 12:06 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!weretis.net!feeder8.news.weretis.net!news.neodome.net!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: retroguy@novabbs.com (Retro Guy)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Fri, 6 Sep 2024 12:06:32 +0000
Organization: Rocksolid Light
Message-ID: <7e23f0180a430b8429af2514ba56463b@www.novabbs.org>
References: <7e8b459c7297ad24dde92aa1fd073b21@www.novabbs.com> <877cbx4orz.fsf@tilde.institute> <51e8c77eaba5ea4084d0a234a71a4f2e@www.novabbs.com> <vbdoi9$m19l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1054804"; mail-complaints-to="usenet@i2pn2.org";
posting-account="gg+dDWHMzVrdxGO9Gmt8aqyeWDXqlxfqiuS0jX/WMXY";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: a93aefeeff923def71455caae2dbfb277a59e046
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Site: $2y$10$UOABu3AZl49qirfUHbXHYOJoM/8oiQSxRv7gA.Y4XMpq32kTKIk0e
X-Face: .&YR-G(w(DZ$$,}%k=]*5*!p'=(anr"IT`wZG'2VWdfl\r)l[42u7JH`n(JUQ*e5*A|XCDf
?&\X&uwkl38"CYX3O8m}C8E4p'%N$2#kSTVzx{Ly|DjLT\Vk7NE}NQ(VC$Yq]i:7|z[.9iv^g>*8_B
H0=hZt'[%)4kG|
View all headers

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 '$'

--
Retro Guy

Subject: Re: perl test
From: Lawrence D'Oliv
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Fri, 6 Sep 2024 23:38 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Fri, 6 Sep 2024 23:38:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <vbg3ov$1080u$4@dont-email.me>
References: <7e8b459c7297ad24dde92aa1fd073b21@www.novabbs.com>
<877cbx4orz.fsf@tilde.institute>
<51e8c77eaba5ea4084d0a234a71a4f2e@www.novabbs.com>
<vbdoi9$m19l$1@dont-email.me>
<7e23f0180a430b8429af2514ba56463b@www.novabbs.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 07 Sep 2024 01:38:08 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2fb14b8e7359fe92374260b719a3728e";
logging-data="1056798"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mXVWqKcb8O+e4qK6hNC8h"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:p5c7dWlbD5ZD9/lvZ4whYvteK5I=
View all headers

On Fri, 6 Sep 2024 12:06:32 +0000, Retro Guy wrote:

> On Fri, 6 Sep 2024 2:14:33 +0000, Lawrence D'Oliveiro wrote:
>
>> «str-expr».replace('"', '""')
>
> The Perl code above escapes quotes, so adds '\' before any "

All right, then:

«str-expr».replace('"', '\\"')

Subject: Re: perl test
From: Retro Guy
Newsgroups: misc.test, comp.lang.misc
Organization: i2pn2 (i2pn.org)
Date: Fri, 6 Sep 2024 23:51 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: retroguy@novabbs.com (Retro Guy)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Fri, 6 Sep 2024 16:51:15 -0700
Organization: i2pn2 (i2pn.org)
Message-ID: <fc1e9bc33cbbffe2731dc2e3931adeaf8fbeceff@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> <vbg3ov$1080u$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 6 Sep 2024 23:51:15 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="1117010"; 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
View all headers

On Fri, 6 Sep 2024 23:38:08 -0000 (UTC), Lawrence D'Oliveiro wrote:

> On Fri, 6 Sep 2024 12:06:32 +0000, Retro Guy wrote:
>
>> On Fri, 6 Sep 2024 2:14:33 +0000, Lawrence D'Oliveiro wrote:
>>
>>> «str-expr».replace('"', '""')
>>
>> The Perl code above escapes quotes, so adds '\' before any "
>
> All right, then:
>
> «str-expr».replace('"', '\\"')

That's readable and makes sense.

Now I'm back to php where I somewhat know what I'm doing :)

Subject: Re: perl test
From: Lawrence D'Oliv
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 00:46 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sat, 7 Sep 2024 00:46:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <vbg7pg$10n40$1@dont-email.me>
References: <7e8b459c7297ad24dde92aa1fd073b21@www.novabbs.com>
<877cbx4orz.fsf@tilde.institute>
<51e8c77eaba5ea4084d0a234a71a4f2e@www.novabbs.com>
<vbdoi9$m19l$1@dont-email.me>
<7e23f0180a430b8429af2514ba56463b@www.novabbs.org>
<vbg3ov$1080u$4@dont-email.me>
<fc1e9bc33cbbffe2731dc2e3931adeaf8fbeceff@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 07 Sep 2024 02:46:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2fb14b8e7359fe92374260b719a3728e";
logging-data="1072256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sF5bcuns5YXLu/w9JJzuT"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:5ReDTVqPBQd//57K8oaBfC9HGrE=
View all headers

On Fri, 6 Sep 2024 16:51:15 -0700, Retro Guy wrote:

> On Fri, 6 Sep 2024 23:38:08 -0000 (UTC), Lawrence D'Oliveiro wrote:
>
>> «str-expr».replace('"', '\\"')
>
> That's readable and makes sense.

Can also be

«str-expr».replace('"', r'\"')

> Now I'm back to php where I somewhat know what I'm doing :)

Aagh.

Subject: Re: perl test
From: Peter Dean
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 03:01 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.dean@gmx.com (Peter Dean)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sat, 7 Sep 2024 03:01:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Sender: <peter@flo.localdomain>
Message-ID: <vbgflq$15f5c$1@dont-email.me>
References: <7e8b459c7297ad24dde92aa1fd073b21@www.novabbs.com> <877cbx4orz.fsf@tilde.institute> <51e8c77eaba5ea4084d0a234a71a4f2e@www.novabbs.com> <vbdoi9$m19l$1@dont-email.me> <7e23f0180a430b8429af2514ba56463b@www.novabbs.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 07 Sep 2024 05:01:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dcd945fd0f0ad96b43bf55fe8ad14c00";
logging-data="1227948"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iau16sK0hWgGU9TENBcOx"
User-Agent: tin/2.6.3-20231224 ("Banff") (Linux/6.6.49-1-lts (x86_64))
Cancel-Lock: sha1:MFgqQLCUb4TERT+nQUnG2htP3MM=
View all headers

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

Subject: Re: perl test
From: Lawrence D'Oliv
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 08:11 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sat, 7 Sep 2024 08:11:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <vbh1rq$1938b$7@dont-email.me>
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=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 07 Sep 2024 10:11:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2fb14b8e7359fe92374260b719a3728e";
logging-data="1346827"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19D62IkqMWty0+sjz1ItYsq"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:H5XDJLrDwNdNqw71qMoIkWI30qg=
View all headers

On Sat, 7 Sep 2024 03:01:14 -0000 (UTC), Peter Dean wrote:

> would it hurt to backslash everything nonalphanumeric?

Does Perl have the equivalent of Python’s re.escape
<https://docs.python.org/3/library/re.html#re.escape>?

Subject: Re: perl test
From: Peter Dean
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 08:19 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.dean@invalid.net (Peter Dean)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sat, 7 Sep 2024 08:19:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Sender: <peter@flo.localdomain>
Message-ID: <vbh2ap$198e2$1@dont-email.me>
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> <vbh1rq$1938b$7@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 07 Sep 2024 10:19:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dcd945fd0f0ad96b43bf55fe8ad14c00";
logging-data="1352130"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194TAkHw+05YnUHNTaU2Glg"
User-Agent: tin/2.6.3-20231224 ("Banff") (Linux/6.6.49-1-lts (x86_64))
Cancel-Lock: sha1:y60FKggeJPdSP+ftVDBINaD3QKk=
View all headers

In comp.lang.misc Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Sat, 7 Sep 2024 03:01:14 -0000 (UTC), Peter Dean wrote:
>
>> would it hurt to backslash everything nonalphanumeric?
>
> Does Perl have the equivalent of Python’s re.escape
> <https://docs.python.org/3/library/re.html#re.escape>?

perldoc -f quotemeta

I thought I already said that. oops.

Subject: Re: perl test
From: Peter Dean
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 09:18 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.dean@invalid.net (Peter Dean)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sat, 7 Sep 2024 09:18:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Sender: <peter@flo.localdomain>
Message-ID: <vbh5ps$1adl0$1@dont-email.me>
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> <vbh1rq$1938b$7@dont-email.me> <vbh2ap$198e2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 07 Sep 2024 11:18:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dcd945fd0f0ad96b43bf55fe8ad14c00";
logging-data="1390240"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+v20obvTwhJzsb0+Bgwto9"
User-Agent: tin/2.6.3-20231224 ("Banff") (Linux/6.6.49-1-lts (x86_64))
Cancel-Lock: sha1:parzORlN9oiVKPAmNEToKZSfEPc=
View all headers

In comp.lang.misc Peter Dean <p.dean@invalid.net> wrote:
> In comp.lang.misc Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>> On Sat, 7 Sep 2024 03:01:14 -0000 (UTC), Peter Dean wrote:
>>
>>> would it hurt to backslash everything nonalphanumeric?
>>
>> Does Perl have the equivalent of Python’s re.escape
>> <https://docs.python.org/3/library/re.html#re.escape>?
>
> perldoc -f quotemeta
>
> I thought I already said that. oops.

Actually reread it myself and realised it won't do the right thing with $.
Ignore me.

Subject: Re: perl test
From: Retro Guy
Newsgroups: misc.test, comp.lang.misc
Organization: i2pn2 (i2pn.org)
Date: Sat, 7 Sep 2024 12:07 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: retroguy@novabbs.com (Retro Guy)
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
View all headers

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.

Subject: Re: perl test
From: Peter Dean
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 14:30 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.dean@invalid.net (Peter Dean)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sat, 7 Sep 2024 14:30:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Sender: <peter@flo.localdomain>
Message-ID: <vbho1a$1d9er$1@dont-email.me>
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> <66f114a9d20bf03cfb305a04d807da6492511772@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 07 Sep 2024 16:30:03 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dcd945fd0f0ad96b43bf55fe8ad14c00";
logging-data="1484251"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AecxuRRCRWPO2ZoFglpYB"
User-Agent: tin/2.6.3-20231224 ("Banff") (Linux/6.6.49-1-lts (x86_64))
Cancel-Lock: sha1:ve4C2IF6Gf6TwGTl+0QUUF97DAo=
View all headers

In comp.lang.misc Retro Guy <retroguy@novabbs.com> wrote:
> 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.

Your way looks good. Nearly identical to solution in chapter 1.18 of "Perl Cookbook"
by Tom Christiansen.

$var =~ s/([CHARLIST])/\\$1/g;

Subject: Re: perl test
From: Lawrence D'Oliv
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 22:59 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sat, 7 Sep 2024 22:59:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <vbilst$1j26j$5@dont-email.me>
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>
<66f114a9d20bf03cfb305a04d807da6492511772@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 08 Sep 2024 00:59:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="5b47ecd330ac087ccb2ea7289cdcbed3";
logging-data="1673427"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1878503z0q+RyswF71mhP+Y"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:YuKpQj4AFsaS9L1FlF4zXb4bJSY=
View all headers

On Sat, 7 Sep 2024 05:07:13 -0700, Retro Guy wrote:

> My use case was escaping a set of strings for use in a command line.

If you want to pass arguments to an external program, don’t bother going
through a shell if you can help it. Invoke the program and pass the
command-line arguments directly, then you don’t have to worry about shell
specials.

Subject: Re: perl test
From: Retro Guy
Newsgroups: misc.test, comp.lang.misc
Organization: Rocksolid Light
Date: Sat, 7 Sep 2024 23:11 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.quux.org!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: retroguy@novabbs.com (Retro Guy)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sat, 7 Sep 2024 23:11:41 +0000
Organization: Rocksolid Light
Message-ID: <aa09ee406562579bb1c5723aaeffe953@www.novabbs.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> <66f114a9d20bf03cfb305a04d807da6492511772@i2pn2.org> <vbilst$1j26j$5@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1233398"; mail-complaints-to="usenet@i2pn2.org";
posting-account="gg+dDWHMzVrdxGO9Gmt8aqyeWDXqlxfqiuS0jX/WMXY";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$8D6Z2BbiGfymLf0U4Dru..31gLdQfU7pPsz0YAjAP79AjJHRYmbk2
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Posting-User: a93aefeeff923def71455caae2dbfb277a59e046
X-Face: .&YR-G(w(DZ$$,}%k=]*5*!p'=(anr"IT`wZG'2VWdfl\r)l[42u7JH`n(JUQ*e5*A|XCDf
?&\X&uwkl38"CYX3O8m}C8E4p'%N$2#kSTVzx{Ly|DjLT\Vk7NE}NQ(VC$Yq]i:7|z[.9iv^g>*8_B
H0=hZt'[%)4kG|
View all headers

On Sat, 7 Sep 2024 22:59:41 +0000, Lawrence D'Oliveiro wrote:

> On Sat, 7 Sep 2024 05:07:13 -0700, Retro Guy wrote:
>
>> My use case was escaping a set of strings for use in a command line.
>
> If you want to pass arguments to an external program, don’t bother going
> through a shell if you can help it. Invoke the program and pass the
> command-line arguments directly, then you don’t have to worry about
> shell
> specials.

That would be my preference, but I'm not sure how to do that from Perl.

My use case is internal (not code expected to run anywhere else), so
this works, but I should put some time into learning how to invoke the
php program from Perl properly when I have some time.

--
Retro Guy

Subject: Re: perl test
From: Lawrence D'Oliv
Newsgroups: misc.test, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sun, 8 Sep 2024 06:38 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sun, 8 Sep 2024 06:38:17 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <vbjgop$1r6qd$1@dont-email.me>
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>
<66f114a9d20bf03cfb305a04d807da6492511772@i2pn2.org>
<vbilst$1j26j$5@dont-email.me>
<aa09ee406562579bb1c5723aaeffe953@www.novabbs.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 08 Sep 2024 08:38:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="5b47ecd330ac087ccb2ea7289cdcbed3";
logging-data="1940301"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qYnnEou/CA227wrAf7x5n"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:l9jPiv5iI2Z0A6jcnZp/R5fxt9Y=
View all headers

On Sat, 7 Sep 2024 23:11:41 +0000, Retro Guy wrote:

> On Sat, 7 Sep 2024 22:59:41 +0000, Lawrence D'Oliveiro wrote:
>
>> If you want to pass arguments to an external program, don’t bother
>> going through a shell if you can help it. Invoke the program and pass
>> the command-line arguments directly, then you don’t have to worry about
>> shell specials.
>
> That would be my preference, but I'm not sure how to do that from Perl.

From the perlfunc(1) man page:

system LIST
system PROGRAM LIST
Does exactly the same thing as "exec", except that a fork
is done first and the parent process waits for the child
process to exit. Note that argument processing varies
depending on the number of arguments. If there is more than
one argument in LIST, or if LIST is an array with more than
one value, starts the program given by the first element of
the list with arguments given by the rest of the list. If
there is only one scalar argument, the argument is checked
for shell metacharacters, and if there are any, the entire
argument is passed to the system's command shell for
parsing (this is "/bin/sh -c" on Unix platforms, but varies
on other platforms). If there are no shell metacharacters
in the argument, it is split into words and passed directly
to "execvp", which is more efficient.

Subject: Re: perl test
From: Retro Guy
Newsgroups: misc.test, comp.lang.misc
Organization: Rocksolid Light
Date: Sun, 8 Sep 2024 11:46 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!panix!weretis.net!feeder9.news.weretis.net!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: retroguy@novabbs.com (Retro Guy)
Newsgroups: misc.test,comp.lang.misc
Subject: Re: perl test
Date: Sun, 8 Sep 2024 11:46:44 +0000
Organization: Rocksolid Light
Message-ID: <d74c8bd2596c112523ffb820eb6f24e5@www.novabbs.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> <66f114a9d20bf03cfb305a04d807da6492511772@i2pn2.org> <vbilst$1j26j$5@dont-email.me> <aa09ee406562579bb1c5723aaeffe953@www.novabbs.org> <vbjgop$1r6qd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1292072"; mail-complaints-to="usenet@i2pn2.org";
posting-account="gg+dDWHMzVrdxGO9Gmt8aqyeWDXqlxfqiuS0jX/WMXY";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$7UaME3aw9ucYpWdo3GITeOKgYHzPoY7AVelrADfbkDIrXJSqH3BaS
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Face: .&YR-G(w(DZ$$,}%k=]*5*!p'=(anr"IT`wZG'2VWdfl\r)l[42u7JH`n(JUQ*e5*A|XCDf
?&\X&uwkl38"CYX3O8m}C8E4p'%N$2#kSTVzx{Ly|DjLT\Vk7NE}NQ(VC$Yq]i:7|z[.9iv^g>*8_B
H0=hZt'[%)4kG|
X-Rslight-Posting-User: a93aefeeff923def71455caae2dbfb277a59e046
View all headers

On Sun, 8 Sep 2024 6:38:17 +0000, Lawrence D'Oliveiro wrote:

> On Sat, 7 Sep 2024 23:11:41 +0000, Retro Guy wrote:
>
>> On Sat, 7 Sep 2024 22:59:41 +0000, Lawrence D'Oliveiro wrote:
>>
>>> If you want to pass arguments to an external program, don’t bother
>>> going through a shell if you can help it. Invoke the program and pass
>>> the command-line arguments directly, then you don’t have to worry about
>>> shell specials.
>>
>> That would be my preference, but I'm not sure how to do that from Perl.
>
> From the perlfunc(1) man page:
>
> system LIST
> system PROGRAM LIST
<snip>

Thank you for the info, I've now done some reading about system, exec,
etc. and yes, system looks to be the correct choice.

I'm basically calling a php script and need to wait for it to complete,
then deal with whether a file exists once back in the perl script. This
is all working perfectly fine for me right now, but no reason I can't
improve the method used (do it properly) at some point. I'm sure this
can all be done in Perl (no need for PHP), but I'm able to slap out PHP
code quickly, so it's my first choice.

Thanks again for your input.

--
Retro Guy

1

rocksolid light 0.9.8
clearnet tor