From: | Nabil Sayegh <nas(at)e-trolley(dot)de> |
---|---|
To: | Oliver Elphick <olly(at)lfix(dot)co(dot)uk> |
Cc: | Nabil Sayegh <postgresql(at)e-trolley(dot)de>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: perlsub |
Date: | 2003-10-04 18:03:08 |
Message-ID: | 3F7F0B5C.3040604@e-trolley.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Oliver Elphick wrote:
> 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.
Ok, here's what I got from #perl
I need to 'eval' the string to make it an executable expression.
-------------------------8<-------------------------------
#!/usr/bin/perl
print perlsub('abc','b','123')."\n";
print perlsub('a=b','([^=]+)=(.+)','key:$1;val:$2;')."\n";
sub perlsub
{
my ($data, $pat, $repl) = @_;
eval "\$data =~ s/$pat/$repl/gi";
return $data;
}
-------------------------8<-------------------------------
As a Pl/Perl Function this still doesnt work.
Seems like it's forbidden, as it would allow to execute
arbitrary code :(
-------------------------8<-------------------------------
CREATE FUNCTION perlsub(text, text, text) RETURNS text AS '
my ($data, $pat, $repl) = @_;
eval "\$data =~ s/$pat/$repl/gi";
return $data
' LANGUAGE 'plperl';
-------------------------8<--------------------------------
plasma=# SELECT perlsub('a=b','([^=]+)=(.+)','key:$1;val:$2');
ERROR: creation of function failed: 'eval "string"' trapped by
operation mask at (eval 2) line 3.
Seems like I have to hardcode the regular expression in the function :(
TFYH
--
e-Trolley Sayegh & John, Nabil Sayegh
Tel.: 0700 etrolley /// 0700 38765539
Fax.: +49 69 8299381-8
PGP : http://www.e-trolley.de
From | Date | Subject | |
---|---|---|---|
Next Message | Anshuman Kanwar | 2003-10-04 19:22:26 | Copy table structure |
Previous Message | Oliver Elphick | 2003-10-04 06:20:10 | Re: perlsub |