I figured out my Perl issue. =~ s/([\"])/\\$1/g; does the trick.
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('"', '""')
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 "
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('"', '\\"')
On Fri, 6 Sep 2024 23:38:08 -0000 (UTC), Lawrence D'Oliveiro wrote:
«str-expr».replace('"', '\\"')
That's readable and makes sense.
Now I'm back to php where I somewhat know what I'm doing :)
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?
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>?
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.
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
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.
My use case was escaping a set of strings for use in a command line.
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.
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.
On Sat, 7 Sep 2024 23:11:41 +0000, Retro Guy wrote:<snip>
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
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (0 / 10) |
Uptime: | 81:41:20 |
Calls: | 12,949 |
Calls today: | 3 |
Files: | 186,574 |
Messages: | 3,264,673 |