Re: perlsub - Mailing list pgsql-novice

From Jeff Eckermann
Subject Re: perlsub
Date
Msg-id 20031007221644.5233.qmail@web20802.mail.yahoo.com
Whole thread Raw
In response to Re: perlsub  (Oliver Elphick <olly@lfix.co.uk>)
List pgsql-novice
Ok, using plperlu:

jeck=# select s('fred','(fr)(ed)', '$1');
 s
----
 fr
(1 row)

jeck=# select s('fred','(fr)(ed)', '$2');
 s
----
 ed
(1 row)

jeck=# select s('fred','(fr)(ed)', '$2 $1');
ERROR:  plperl: error from function: syntax error at
(eval 7) line 2, near "$2 $1
"

jeck=# select s('fred','(fr)(ed)', '$2." ".$1');
   s
-------
 ed fr
(1 row)

So, the string to be evaluated must meet normal perl
syntactic rules for an expression.

The example you gave worked fine for me from the
command line because I was typing the "$2 $1" directly
into the regex, so one interpolation did the job.  In
the function the first interpolation placed the
argument string into the regex, not the value of the
variable, so the eval (s/.../.../ee) is needed to get
the value.

Hmm, maybe this was off-topic after all ;-)

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

pgsql-novice by date:

Previous
From: Jeff Eckermann
Date:
Subject: Re: perlsub
Next
From: David Rickard
Date:
Subject: Dropping Databases