Re: perl test

Liste des GroupesRevenir à m test 
Sujet : Re: perl test
De : p.dean (at) *nospam* invalid.net (Peter Dean)
Groupes : misc.test comp.lang.misc
Date : 07. Sep 2024, 15:30:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbho1a$1d9er$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : tin/2.6.3-20231224 ("Banff") (Linux/6.6.49-1-lts (x86_64))
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;

Date Sujet#  Auteur
31 Aug 24 * perl test19Retro Guy
31 Aug 24 +- Re: perl test1Retro Guy
31 Aug 24 `* Re: perl test17yeti
31 Aug 24  `* Re: perl test16Retro Guy
6 Sep 24   `* Re: perl test15Lawrence D'Oliveiro
6 Sep 24    `* Re: perl test14Retro Guy
7 Sep 24     +* Re: perl test3Lawrence D'Oliveiro
7 Sep 24     i`* Re: perl test2Retro Guy
7 Sep 24     i `- Re: perl test1Lawrence D'Oliveiro
7 Sep 24     `* Re: perl test10Peter Dean
7 Sep 24      +* Re: perl test3Lawrence D'Oliveiro
7 Sep 24      i`* Re: perl test2Peter Dean
7 Sep 24      i `- Re: perl test1Peter Dean
7 Sep 24      `* Re: perl test6Retro Guy
7 Sep 24       +- Re: perl test1Peter Dean
8 Sep 24       `* Re: perl test4Lawrence D'Oliveiro
8 Sep 24        `* Re: perl test3Retro Guy
8 Sep 24         `* Re: perl test2Lawrence D'Oliveiro
8 Sep 24          `- Re: perl test1Retro Guy

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal