Re: Plperl and my() lexical variables bug?

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Plperl and my() lexical variables bug?
Дата
Msg-id 20060623140613.GF8900@svana.org
обсуждение исходный текст
Ответ на Re: Plperl and my() lexical variables bug?  (Michael Fuhr <mike@fuhr.org>)
Список 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@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Alban Hertroys
Дата:
Сообщение: Re: JUST NOT ADDING UP
Следующее
От: Scott Ribe
Дата:
Сообщение: Re: Return the primary key of a newly inserted row?