Re: pl/perl function life and variable scope - - Mailing list pgsql-general

From Christopher Murtagh
Subject Re: pl/perl function life and variable scope -
Date
Msg-id 1068672289.2593.17.camel@mafalda.murtagh.name
Whole thread Raw
In response to Re: pl/perl function life and variable scope - concurrency  ("Joshua D. Drake" <jd@commandprompt.com>)
List pgsql-general
On Wed, 2003-11-12 at 15:44, Joshua D. Drake wrote:
> Or in other words... code to "strict"

 :-)

 Yes, I do normally. I was simply running a test and came across this
and it caught me by surprise. For the record, my pl/perl function is
this:

CREATE OR REPLACE FUNCTION htdig(text, text)
RETURNS text[] AS '

 my $SearchTerms = $_[0];
 my $HtDigDB = $_[1];
 my @Result = {};
 my $Line = '''';

 #open HTDIG, "/usr/local/htdig/bin/htsearch  ''config=" . $HtDigDB . ";words=" . $SearchTerms .
"'';matchesperpage=1000;";
 open HTDIG, "/bin/cat /home/postgres/" . $SearchTerms . " |";

 while(<HTDIG>) {

    $Line = $_;
    $Line =~ s/^h[^0-9]*//;
    chomp($Line);
    push @Result, $Line;
 }

 close HTDIG;

 return qq/{/ . (join qq/,/, @Result) . qq/}/;
' LANGUAGE plperlu;


I started writing this in C and realized that this was going to be a
couple hundred lines of code - compared to the 23 lines in Perl,
including test lines. All this function needs to do is to take a pipe
from the htsearch and grab integers in the URL that it returns. Then
I'll write a pl/pgSQL wrapper that returns this array as a set.

Pretty sweet, and I couldn't have done it without the help of this list.

Thanks!

Cheers,

Chris

--
Christopher Murtagh
Enterprise Systems Administrator
ISR / Web Communications Group
McGill University
Montreal, Quebec
Canada

Tel.: (514) 398-3122
Fax:  (514) 398-2017

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: serial type vs. sequences
Next
From: "scott.marlowe"
Date:
Subject: Re: SQL-question: returning the id of an insert querry