Search Postgresql Archives

Re: Plperl and my() lexical variables bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux