Re: Plperl and my() lexical variables bug?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: Philippe Lang <philippe(dot)lang(at)attiksystem(dot)ch>, pgsql-general(at)postgresql(dot)org
Subject: Re: Plperl and my() lexical variables bug?
Date: 2006-06-23 14:06:13
Message-ID: 20060623140613.GF8900@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jun 23, 2006 at 07:49:19AM -0600, Michael Fuhr wrote:
> This behavior isn't specific to PL/Perl. A standalone Perl program
> exhibits the same behavior, so you might find a better explanation
> in a Perl-specific forum like the comp.lang.perl.misc newsgroup.

If you run it standalone with warnings enabled, you get this:

Variable "$val" will not stay shared at a.pl line 6.

Which is pretty much what is happening. There's plenty written about
this on the web. This has a good summary as well as solutions:

http://perl.com/pub/a/2002/05/07/mod_perl.html

In particular, if you "use diagnostics" it suggests an anonymous sub
will deal with it.

Hope this helps,

---- a.pl ----
use warnings;
use diagnostics;

sub test
{
my $val;

sub init {
$val = $_[0];
print( "1: $_[0] " . \$val . "\n");
}

init(12);
print("2: $val " . \$val . "\n");

}

test;
test;
--- snip ---
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Ribe 2006-06-23 15:09:23 Re: Return the primary key of a newly inserted row?
Previous Message Alban Hertroys 2006-06-23 14:00:02 Re: JUST NOT ADDING UP