Limitations in PL/perl
Folks,
Is there any documentation anywhere on what subset of Perl functionality is
supported by PL/perl? I've had a lot of annoying trial-and-error sessions
lately where I'll try something that works on the command line only to find
out that it silently fails in PL/perl.
For example:
On the command line:
$some_text =~ s/\W|\s//g;
... works great to remove all punctuation and spaces in a string.
But in PL/perl, I have to use:
$some_text =~ s/[^A-Za-z0-9]/""/eg;
Or is this maybe a problem with the version of Perl installed on the DB
server?
Thanks for any help.
--
-Josh Berkus
Aglio Database Solutions
San Francisco
Josh Berkus <josh@agliodbs.com> writes:
Is there any documentation anywhere on what subset of Perl functionality is
supported by PL/perl? I've had a lot of annoying trial-and-error sessions
lately where I'll try something that works on the command line only to find
out that it silently fails in PL/perl.
For example:
On the command line:
$some_text =~ s/\W|\s//g;
... works great to remove all punctuation and spaces in a string.
But in PL/perl, I have to use:
$some_text =~ s/[^A-Za-z0-9]/""/eg;
AFAIK, either of these should work in plperl. Did you remember to
double those backslashes while entering the function text?
regards, tom lane
Tom,
AFAIK, either of these should work in plperl. Did you remember to
double those backslashes while entering the function text?
D'oh! Now I feel really dumb ...
--
Josh Berkus
Aglio Database Solutions
San Francisco
Josh Berkus wrote:
Is there any documentation anywhere on what subset of Perl functionality is
supported by PL/perl? I've had a lot of annoying trial-and-error sessions
lately where I'll try something that works on the command line only to find
out that it silently fails in PL/perl.
[...snip...]
Or is this maybe a problem with the version of Perl installed on the DB
server?
I think it is probably a problem with the version of Perl installed on
the DB server. As far as I can see, plperl just runs a perl interpreter
using whatever perl shared library it finds. That is except plperl (as
compared to plperlu) runs a "safe" interpreter with certain
functionality disabled -- but I don't know the details of what is disabled.
I can see this in the source:
plperl_init_interp(void)
{
char *embedding[3] = {
"", "-e",
/*
* no commas between the next 5 please. They are supposed to be
* one string
*/
"require Safe; SPI::bootstrap();"
"sub ::mksafefunc { my $x = new Safe;
$x->permit_only(':default');$x->permit(':base_math');"
"$x->share(qw[&elog &DEBUG &LOG &INFO &NOTICE &WARNING &ERROR]);"
" return $x->reval(qq[sub { $_[0] }]); }"
"sub ::mkunsafefunc {return eval(qq[ sub { $_[0] } ]); }"
};
Not sure if that helps.
Joe