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

From Thomas A. Lowery
Subject Re: pl/perl Documentation
Date
Msg-id 20020523012657.A31461@stllnx1.stlassoc.com
Whole thread Raw
In response to Re: pl/perl Documentation  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
> CREATE FUNCTION remspace(TEXT) RETURNS TEXT AS '
>     return map { s/\s*// } @_;
> ' LANGUAGE 'plperl' WITH (isstrict);

This may or may not do what you're looking for.
s/\s*// or s/\s+// removes only the spaces from the first occurrence to
the before first non-space character.

To remove all the spaces from the string then:
s/\s+//g

To strip or trim the beginning and ending spaces.
s/^\s+//
s/\s+$//

Tom

> > "Duncan Adams  (DNS)" <duncan.adams@vcontractor.co.za> writes:
> >
> > 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.


pgsql-novice by date:

Previous
From: Ron Johnson
Date:
Subject: Re: optimising data load
Next
From: John Taylor
Date:
Subject: Re: optimising data load