[thelist] perl: inlining functions + postgres triggers

David Siedband technique at oceanicsky.com
Sat Jul 30 14:30:02 CDT 2005

I'm using a trigger in PostgreSQL to override an insert query and  
build a wget request that calls a python object on separate machine.   
I need to encode the fields (escape spaces, etc.) so they can be  
passed as a valid URL. It seems I can't import modules with 'use' or  
do subroutines, so I'd like to just inline the function.

Here is the plperlu statement that works when there are no spaces in  
the $body variable:

CREATE OR REPLACE FUNCTION customerfolder_add (text,text) RETURNS  
text as '
   $body = shift;
   $phone = shift;
   $sec = "--http-user=userNameHere --http-passwd=passWordHere";
   $portal = "/Plone";
   $server = "localhost:8080";
   $wget = "/usr/bin/wget";
   $cmd = "$wget $sec -q -O - http://$server/$portal/create_customer? 
body=$body" . '&phone' . "=$phone";
   return `$cmd`;
' LANGUAGE plperlu;

Here is the subroutine I want to apply this function to $body.

sub URLEncode {
    my $theURL = $_[0];
    $theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
    return $theURL;

How do I inline the above function and apply to the $body variable?


More information about the thelist mailing list