Re: perlsub

From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: Nabil Sayegh <postgresql(at)e-trolley(dot)de>, Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: perlsub
Date: 2003-10-07 22:16:44
Message-ID: 20031007221644.5233.qmail@web20802.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

  • Re: perlsub at 2003-10-07 21:18:01 from Oliver Elphick

Browse pgsql-novice by date

  From Date Subject
Next Message David Rickard 2003-10-07 22:53:12 Dropping Databases
Previous Message Jeff Eckermann 2003-10-07 21:49:11 Re: perlsub