Re: pl/perl Documentation

Поиск
Список
Период
Сортировка
От Thomas A. Lowery
Тема Re: pl/perl Documentation
Дата
Msg-id 20020523012657.A31461@stllnx1.stlassoc.com
обсуждение исходный текст
Ответ на Re: pl/perl Documentation  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Ron Johnson
Дата:
Сообщение: Re: optimising data load
Следующее
От: John Taylor
Дата:
Сообщение: Re: optimising data load