Re: perlsub - Mailing list pgsql-novice

From Oliver Elphick
Subject Re: perlsub
Date
Msg-id 1065248410.4459.95.camel@linda.lfix.co.uk
Whole thread Raw
In response to perlsub  (Nabil Sayegh <postgresql@e-trolley.de>)
Responses Re: perlsub  (Nabil Sayegh <nas@e-trolley.de>)
List pgsql-novice
On Sat, 2003-10-04 at 00:29, Nabil Sayegh wrote:
> Hello again,
>
> now that perlsub works i need to know how backreferences work with
> plperl. $1 - $9 doesn't work. Any idea ?
>
> perlsub:
> -----------------------------------------------
> CREATE FUNCTION perlsub(text, text, text) RETURNS text AS '
>      my ($data, $pat, $repl) = @_;
>      $data =~ s/$pat/$repl/;
>      return $data
> ' LANGUAGE 'plperl';
> -----------------------------------------------
>
> SELECT perlsub('a=b','([^=]+)=(.+)','key:$1;val:$2');
>
> Any idea ? Just a matter of quoting ?

It's a problem with Perl itself rather than with PL/Perl.  I tried that
in a Perl script and it produces the same result.  I couldn't find any
way of including $ in the replacement string as a metacharacter.

You need to consult a Perl guru.

When you do get an example that works in a script, remember to double
any single quotes and backslashes when you create the function.

> Also this example doesn't work with * instead of + :(

I don't see any difference:

junk=# SELECT perlsub('a=b','([^=]*)=(.*)','key:$1;val:$2');
    perlsub
---------------
 key:$1;val:$2
(1 row)

junk=# SELECT perlsub('a=b','([^=]+)=(.+)','key:$1;val:$2');
    perlsub
---------------
 key:$1;val:$2
(1 row)


--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "For the word of God is quick, and powerful, and
      sharper than any twoedged sword, piercing even to the
      dividing asunder of soul and spirit, and of the joints
      and marrow, and is a discerner of the thoughts and
      intents of the heart."        Hebrews 4:12


pgsql-novice by date:

Previous
From: Nabil Sayegh
Date:
Subject: perlsub
Next
From: Martin_vi_Lange@t-online.de (Martin Lange)
Date:
Subject: Re: perlsub