Re: PlPerl scope issue - Mailing list pgsql-general

From Andy Colson
Subject Re: PlPerl scope issue
Date
Msg-id 4B2962C4.4050804@squeakycode.net
Whole thread Raw
In response to Re: PlPerl scope issue  ("Peter" <peter@greatnowhere.com>)
List pgsql-general
On 12/16/2009 3:15 PM, Peter wrote:
> Hello Tim,
>
> Thanks for the reply! I'm still not sure why it's bad to have named
> subroutines. At any rate I cant use anon subs since we have a complicated
> reporting subsystem that relies on Perl formulas being eval-ed at runtime,
> and these refer to various subroutines.
>
> I have since resolved the issue by using 'local' scope, but it still beats
> me why variables are not seen in inner subroutines. The same code works in
> plain Perl on the same machine as Postgres, and it also works on second
> 8.4.1 Postgres/FreeBSD box. Glitch Ubuntu Karmic debs perhaps?
>
> Sorry for top-posting... me is being forced to use stooped Outlook...
>
> Peter
>

Becuase (borrowing Martijn's code), you have this:

     my $test=shift;
     test();
     return $test;
     sub test {
        print "X=".$test."\n";
     }

And PG is wrapping your entire source code in a sub, so... it sees:

sub pg-auto-wrap
{
     my $test=shift;
     test();
     return $test;
     sub test {
        print "X=".$test."\n";
     }
}


I'd guess you dont want 'local'.  You probably want 'our'.

I have the same problems in mod_perl.

-Andy


pgsql-general by date:

Previous
From: Tim Hart
Date:
Subject: Re: make check fails on OS X 10.6.2
Next
From: Tom Lane
Date:
Subject: Re: Justifying a PG over MySQL approach to a project