Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

Next:From: John TaylorDate: 2002-05-23 07:01:42
Subject: Re: optimising data load
Previous:From: Ron JohnsonDate: 2002-05-23 02:40:07
Subject: Re: optimising data load

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group