Is there any way to use a nginx variable inside a perl set?

Let’s imagine that I do this

http {
set $a 2;
perl_set $x sub { return $a++; }
}

I don’t think I can do this. Is there away around this to provide that
functionality?

Posted at Nginx Forum:

Hello!

On Tue, Aug 17, 2010 at 05:18:20PM -0400, evms wrote:

Let’s imagine that I do this

http {
set $a 2;
perl_set $x sub { return $a++; }
}

I don’t think I can do this. Is there away around this to provide that
functionality?

Something like this should work (not tested):

perl_set $x “sub {
my $r = shift;
my $a = $r->variable{‘a’};
$a++;
$r->variable(‘a’, $a);
return $a;
}”;

See here for details:

http://wiki.nginx.org/NginxEmbeddedPerlModule

Maxim D.