Re: pl/perl Documentation

From: "Thomas A(dot) Lowery" <tlowery(at)stlowery(dot)net>
To: "Duncan Adams (DNS)" <duncan(dot)adams(at)vcontractor(dot)co(dot)za>, pgsql-novice(at)postgresql(dot)org
Subject: Re: pl/perl Documentation
Date: 2002-05-23 05:26:57
Message-ID: 20020523012657.A31461@stllnx1.stlassoc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)adams(at)vcontractor(dot)co(dot)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.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message John Taylor 2002-05-23 07:01:42 Re: optimising data load
Previous Message Ron Johnson 2002-05-23 02:40:07 Re: optimising data load