Re: Plperl and my() lexical variables bug?

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Plperl and my() lexical variables bug?
Дата
Msg-id 20060623134919.GA68363@winnie.fuhr.org
обсуждение исходный текст
Ответ на Plperl and my() lexical variables bug?  ("Philippe Lang" <philippe.lang@attiksystem.ch>)
Ответы Re: Plperl and my() lexical variables bug?  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
On Fri, Jun 23, 2006 at 11:33:42AM +0200, Philippe Lang wrote:
> Am I missing something maybe? It sounds like a bug with lexical variables to me...

I think what's happening is that sub init is created once with $val
referencing the lexically-scoped $val from sub foo's first invocation.
When you call foo again, foo creates a new lexically-scoped $val
but init's $val still refers to the object from foo's first call.
You can see this if you display \$val:

CREATE OR REPLACE FUNCTION foo() RETURNS void AS $$
    my $val;

    sub init {
        $val = $_[0];
        elog(NOTICE, "1: $_[0] " . \$val);
    }

    init(12);
    elog(NOTICE, "2: $val " . \$val);
$$ LANGUAGE plperl;

SELECT foo();
NOTICE:  1: 12 SCALAR(0x8447220)
NOTICE:  2: 12 SCALAR(0x8447220)
 foo
-----

(1 row)

SELECT foo();
NOTICE:  1: 12 SCALAR(0x8447220)
NOTICE:  2:  SCALAR(0x83f5c4c)
 foo
-----

(1 row)

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.

--
Michael Fuhr

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

Предыдущее
От: "Rhys Stewart"
Дата:
Сообщение: JUST NOT ADDING UP
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: JUST NOT ADDING UP