You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Beau E. Cox" <be...@beaucox.com> on 2002/11/20 11:48:34 UTC

Newbie: how to use PerlSetVar

Hi -

I'm new to mod_perl, so here's my query:

May I use PerlSetVar/PerlAddVar statements in the httpd.conf
file for my own use? What about namespaces, i.e. how
do I avoid stepping on someone else's variable?

Assume I can. How can I access those variables from my mod_perl
scripts?

How can I set variables in a handler (instead of httpd.conf)?

Aloha => Beau.




Re: Newbie: how to use PerlSetVar

Posted by Perrin Harkins <pe...@elem.com>.
domm@zsi.at wrote:

> >What about namespaces, i.e. how
> >do I avoid stepping on someone else's variable?
>
>
> Prepend some custom string in front of the VarName:
>
>  PerlSetVar MyApp_Var1 value1
>  PerlSetVar MyApp_Var2 value2


Also, note that these are scoped within the <Location> block where they 
are defined.  This means you can actually have different values for 
different locations, different virtual hosts, etc.

- Perrin


RE: Newbie: how to use PerlSetVar

Posted by "Beau E. Cox" <be...@beaucox.com>.
Hi - and thank you -

I am RTFM, but when you get into something new (and vast)
it takes a while for the _gestalt_ to happen. You have
given me the kick start I needed. I'll be silent for a 
time coding away ;)

Aloha => Beau.

-----Original Message-----
From: domm@zsi.at [mailto:domm@zsi.at]
Sent: Wednesday, November 20, 2002 1:09 AM
To: Modperl
Subject: Re: Newbie: how to use PerlSetVar


Hi!

On Mit, Nov 20, 2002 at 12:48:34 -1000, Beau E. Cox wrote:

> May I use PerlSetVar/PerlAddVar statements in the httpd.conf
> file for my own use?

Yes. Thats what they are here for.

> What about namespaces, i.e. how
> do I avoid stepping on someone else's variable?

Prepend some custom string in front of the VarName:

 PerlSetVar MyApp_Var1 value1
 PerlSetVar MyApp_Var2 value2

or, a real-life example out of Apache::AuthDBI
http://search.cpan.org/author/ABH/Apache-DBI-0.89/AuthDBI.pm

 PerlSetVar Auth_DBI_data_source   dbi:driver:dsn
 PerlSetVar Auth_DBI_username      db_username
 PerlSetVar Auth_DBI_password      db_password

> Assume I can. How can I access those variables from my mod_perl
> scripts?

short:
$r->dir_config('MyApp_Var1')

long:
http://perl.apache.org/docs/1.0/guide/config.html#PerlSetVar_and_PerlAddVar

I would suggest that you spend some time RTFM either here:
http://perl.apache.org

and/or read some of those books:
http://perl.apache.org/docs/offsite/books.html


-- 
#!/usr/bin/perl
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}



Re: Newbie: how to use PerlSetVar

Posted by do...@zsi.at.
Hi!

On Mit, Nov 20, 2002 at 12:48:34 -1000, Beau E. Cox wrote:

> May I use PerlSetVar/PerlAddVar statements in the httpd.conf
> file for my own use?

Yes. Thats what they are here for.

> What about namespaces, i.e. how
> do I avoid stepping on someone else's variable?

Prepend some custom string in front of the VarName:

 PerlSetVar MyApp_Var1 value1
 PerlSetVar MyApp_Var2 value2

or, a real-life example out of Apache::AuthDBI
http://search.cpan.org/author/ABH/Apache-DBI-0.89/AuthDBI.pm

 PerlSetVar Auth_DBI_data_source   dbi:driver:dsn
 PerlSetVar Auth_DBI_username      db_username
 PerlSetVar Auth_DBI_password      db_password

> Assume I can. How can I access those variables from my mod_perl
> scripts?

short:
$r->dir_config('MyApp_Var1')

long:
http://perl.apache.org/docs/1.0/guide/config.html#PerlSetVar_and_PerlAddVar

I would suggest that you spend some time RTFM either here:
http://perl.apache.org

and/or read some of those books:
http://perl.apache.org/docs/offsite/books.html


-- 
#!/usr/bin/perl
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}