Re: PlPerl scope issue

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Peter <peter(at)greatnowhere(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: PlPerl scope issue
Date: 2009-12-16 22:44:20
Message-ID: 4B2962C4.4050804@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-12-16 22:48:32 Re: Justifying a PG over MySQL approach to a project
Previous Message Tim Hart 2009-12-16 22:24:14 Re: make check fails on OS X 10.6.2