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

**URL:** <https://www.ruby-forum.com/t/is-there-any-way-to-use-a-nginx-variable-inside-a-perl-set/193447>\
**Category:** NGINX\
**Created:** [August 17, 2010, 11:19pm UTC](https://www.ruby-forum.com/t/is-there-any-way-to-use-a-nginx-variable-inside-a-perl-set/193447 "2010-08-17T23:19:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![evms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/34f0e0/32.png) [@evms](https://www.ruby-forum.com/u/evms)\
**Post date:** [August 17, 2010, 11:19pm UTC](https://www.ruby-forum.com/t/is-there-any-way-to-use-a-nginx-variable-inside-a-perl-set/193447/1 "2010-08-17T23:19:11Z")

</div>

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:

> **[Is there any way to use a nginx variable inside a perl set?](https://forum.nginx.org/read.php?2,120809,120809#msg-120809)**
>
> 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?

---

<div class="post-metadata">

**Author:** ![evms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/34f0e0/32.png) [@evms](https://www.ruby-forum.com/u/evms)\
**Post date:** [August 18, 2010, 2:17am UTC](https://www.ruby-forum.com/t/is-there-any-way-to-use-a-nginx-variable-inside-a-perl-set/193447/2 "2010-08-18T02:17:10Z")

</div>

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:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Maxim D.
