From: | Cédric Godin <cedric(dot)godin(at)skynet(dot)be> |
---|---|
To: | "io(dot)sys" <io(dot)sys(at)post(dot)cz>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | postgre novice mail list <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: syntax error in plperl wrapper for Perl regex replace. |
Date: | 2018-08-30 09:20:49 |
Message-ID: | db6225ac-d01c-b59c-16f6-b521aca5a87b@skynet.be |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#FFFFFF" bgcolor="#330033">
<div class="moz-cite-prefix">Le 25/08/18 à 01:55, io.sys a écrit :</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Not being a perl expert either I think
the problem lies in the regex line.</div>
<div class="moz-cite-prefix">You should eval it to have the expected
result (and you can use your 4th parameter again then).</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">eval "s/$_[1]/$_[2]/$_[3]";</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Regards, Cédric<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<blockquote type="cite" cite="mid:20180825015547(dot)0778274b(at)aps(dot)gogo">
<pre class="moz-quote-pre" wrap="">Tom,
You are right, it is a Perl's fault, not Postgre's.
You are right also with assumption, that the "s" command of Perl does not accept variable
in every of it's part. I have narrowed down the problem (btw, I could not find anything
about it is Perl docs) to the options part, ie. after last slash. Perl only accepts literals
there, not a variable of any kind. So these options must be hardcoded, not a dynamic value
constructed at runtime.
This compiles:
s/$_[1]/$_[2]/ig;
But even then, the command does not work as expected, as it does not interpret the
backreferences in a replacement string passed to it. It uses it literally. For example,
one would expect that the following call will return 'Praha':
select perl_regexp_replace ('PRAHA', '^(.)(.*)$', '$1\L$2');
But it returns:
$1\L$2
Well, Perl is praised for it's capabilities at the field of text processing, but this
experience disappointed me a little bit. Never mind, I will solve the things different way.
Thank you all for your inputs.
Regards, Roman Golis.
</pre>
</blockquote>
</body>
</html>
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 2.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | io.sys | 2018-08-31 04:06:32 | Re: syntax error in plperl wrapper for Perl regex replace. |
Previous Message | io.sys | 2018-08-24 23:55:47 | Re: syntax error in plperl wrapper for Perl regex replace. |