Re: pl/perl Documentation - Mailing list pgsql-novice

From Tom Lane
Subject Re: pl/perl Documentation
Date
Msg-id 24004.1022077488@sss.pgh.pa.us
Whole thread Raw
In response to pl/perl Documentation  ("Duncan Adams (DNS)" <duncan.adams@vcontractor.co.za>)
Responses Re: pl/perl Documentation  ("Joshua b. Jore" <josh@greentechnologist.org>)
List pgsql-novice
"Duncan Adams  (DNS)" <duncan.adams@vcontractor.co.za> writes:
> CREATE or REPLACE FUNCTION remspace(TEXT) RETURN TEXT
> AS '
>     @_ =~ s/\s*//;
>     return @_'
> LANGUAGE 'plperl';

I'm not much of a Perl hacker, but even I can see that this is not good
Perl.  You need a semicolon to finish the return statement, and I think
you want to manipulate the first element of the @_ array, not the whole
array.  So something like

CREATE or REPLACE FUNCTION remspace(TEXT) RETURN TEXT AS '
    $_[0] =~ s/\s*//;
    return $_[0];
' LANGUAGE 'plperl';

would probably do what you want.

I'd recommend getting hold of a book about Perl.

            regards, tom lane

pgsql-novice by date:

Previous
From: Tom Sheehan
Date:
Subject: Re: Better way to bulk-load millions of CSV records into postgres?
Next
From: Rasmus Mohr
Date:
Subject: Re: optimising data load