Обсуждение: Cleaning text with function?

Поиск
Список
Период
Сортировка

Cleaning text with function?

От
"Patrick Hatcher"
Дата:
Currently I have a perl script that I use to cleanse text fields in a file
for use in our mainframe.  I would like to do this as a function and bypass
using perl if possible.  Is this possible?  I do not have plperl installed
on the database due to server restrictions.
Example of current perl statement:

while (<>) {        # Streams the corrected text back to the original file

        s/¨/ /g;    # Character replace
         s/ª/ /g;    # Character replace
        s/`/ /g;    # Character replace
         s/¡/ /g;    # Character replace
        s/Ë/A/g;    # Character replace
        s/Ò/ /g;    # Character replace
        s/Ó/ /g;    # Character replace
        s/æ/E/g;    # Character replace
        s/ê/I/g;    # Character replace
        s/ì/I/g;    # Character replace
        s/ï/O/g;    # Character replace

        print;          # this goes to the temp filehandle, ARGVOUT,
               # not STDOUT as usual, so don't mess with it !
}

TIA

Patrick Hatcher
Macys.Com
Legacy Integration Developer





Re: Cleaning text with function?

От
"Josh Berkus"
Дата:
Patrick,

> Currently I have a perl script that I use to cleanse text fields in a
> file
> for use in our mainframe.  I would like to do this as a function and
> bypass
> using perl if possible.  Is this possible?  I do not have plperl
> installed
> on the database due to server restrictions.
> Example of current perl statement:

I'm afraid that you really need PL/Perl or PL/Tcl for this.

 While it would be possible to do the text replacement with PL/pgSQL or
pglibq, it would be much, much slower -- basically, you'd need to loop
through the text character-by-character and test each character for the
correct types.   If you want an example of this approach, search the
archives of the SQL list for the STRIPNUMERIC function which I posted
some time ago.


 Perl and Tcl are known for their superior text-processing capabilities
for a reason.

-Josh Berkus