syntax error in plperl wrapper for Perl regex replace.

From: "io(dot)sys" <io(dot)sys(at)post(dot)cz>
To: pgsql-novice(at)postgresql(dot)org
Subject: syntax error in plperl wrapper for Perl regex replace.
Date: 2018-08-23 17:20:05
Message-ID: 20180823192005.639d4531@aps.gogo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

I am trying to create a simple wrapper to use Perl regexp replace capabilites, which
supports \L (aka "lowercase from here on") in a replacement-strings, not available in
postgre native regexp functions.

Based on this article:
https://www.anchor.com.au/blog/2013/09/extending-postgresql-high-level-languages-cats/
I copy-pasted the function code with a little adjustment, leading to:

----------
create or replace function perl_regexp_replace (text, text, text, text)
returns text as $funcbody$

$_=$_[0];
s/$_[1]/$_[2]/$_[3];
return $_;

$funcbody$ language plperl immutable;
----------

When running the above code, I get a syntax error in the line "s/..".

When I remove this line, the function compiles, but (of course) does not do anything
usefull.

So, what is wrong with line:
s/$_[1]/$_[2]/$_[3];

Thank in advance for reply.

R.Golis, Prague.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message io.sys 2018-08-24 01:32:49 Re: syntax error in plperl wrapper for Perl regex replace.
Previous Message Mike Dewhirst 2018-08-23 01:27:45 Thank you [Was: Switching from 9.1 to 9.5 on Ubuntu 16.04]