You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by x x <sc...@hotmail.com> on 2005/06/27 18:04:04 UTC
Declaring variables in a required script
I'm sorry if this question has already been answered, but I couldn't find
the answer.
Here is my problem. I have a script that looks like this:
#!/usr/local/bin/perl -Tw
use strict;
use CGI;
my $q = new CGI;
my $var = $q->param("var");
$var =~ m/(.*)/; #just to don't get any tainted errors, don't use in public.
$var = $1;#just to don't get any tainted errors, don't use in public.
require "/Library/WebServer/mod_perl/$var.pl";
print "Content-Type: text/plain\n\n";
print "1\n" if $lang::varl eq $var;
print "$var\n";
print "$lang::varl\n";
And I have the script nl.pl:
#!/usr/bin/perl -wT
use strict;
$lang::varl = "nl";
And the last one, en.pl:
#!/usr/bin/perl -wT
use strict;
$lang::varl = "en";
So if I make a request a few times with &var=en and then switch to &var=nl
It sometimes happens that I get:
nl
en
So I don't get the 1 ($lang::varl and $var don't eq) and indeed the two
lines don't match ("en\nnl" or also sometimes "nl\nen") $var always has the
right value, the problem is that $lang::varl doesn't always have the right
value.
I am using Apache 1.3.33, mod_perl 1.29 and Mac OS X 10.4.1.
I hope someone could help me. Thank you very much!
Bram.
_________________________________________________________________
Direct antwoord op je vragen: gebruik MSN Messenger http://messenger.msn.nl/
Re: Declaring variables in a required script
Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tom Schindl schrieb:
| Bram x schrieb:
| |> From: Tom Schindl <to...@gmx.at>
[...]
|
| en.pl:
| --------------------------8<--------------------------
| package i18n::pl;
~ ^^^
Should be en.
|
| my %vars = ( lang => 'nl' );
|
| sub getVars {
| ~ return %vars;
| }
|
| 1;
| --------------------------8<--------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCwSjDkVPeOFLgZFIRAkE2AJ42toGSxQWYmJxJHDYrpeAYTL65BQCfeCoj
QMEKox31oybD2VWwaLFkUM4=
=U2NA
-----END PGP SIGNATURE-----
Re: Declaring variables in a required script
Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Bram x schrieb:
|> From: Tom Schindl <to...@gmx.at>
|>
|> -----BEGIN PGP SIGNED MESSAGE-----
|> Hash: SHA1
|>
|> You should learn how perl works. I suppose you are running the script as
|> an Apache::Reqistry but you miss the version.
|>
|> You problem is that if en.pl is loaded using require in a process is
|> will not be reloaded once more hence you lines of code won't be run.
|>
|> If you really want to run the "required" code everytime you are loading
|> it you have to use "do" see perlfunc for more information. Still I'd
|> consider using "do" a bad program design.
|>
|> Tom
|
|
| Thank you, indeed, if I use do(), it works good. I'll read perlfunc.
|
Better you'd do the following:
main.pl:
- --------------------------8<--------------------------
use CGI;
my $lang = $cgi->param('lang');
require "$lang.pl";
my %vars = "i18n::$lang"->getVars();
- --------------------------8<--------------------------
nl.pl:
- --------------------------8<--------------------------
package i18n::nl;
my %vars = ( lang => 'nl' );
sub getVars {
~ return %vars;
}
1;
- --------------------------8<--------------------------
en.pl:
- --------------------------8<--------------------------
package i18n::pl;
my %vars = ( lang => 'nl' );
sub getVars {
~ return %vars;
}
1;
- --------------------------8<--------------------------
| _________________________________________________________________
| Direct antwoord op je vragen: gebruik MSN Messenger
| http://messenger.msn.nl/
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCwSYWkVPeOFLgZFIRAkwAAJ43XdQa324yFy3NhYaa91JZFAmYewCgn9ZV
1GiBNBfgTcS3uRZV5kKFrbc=
=/dbO
-----END PGP SIGNATURE-----
Re: Declaring variables in a required script
Posted by Bram x <sc...@hotmail.com>.
>From: Tom Schindl <to...@gmx.at>
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>You should learn how perl works. I suppose you are running the script as
>an Apache::Reqistry but you miss the version.
>
>You problem is that if en.pl is loaded using require in a process is
>will not be reloaded once more hence you lines of code won't be run.
>
>If you really want to run the "required" code everytime you are loading
>it you have to use "do" see perlfunc for more information. Still I'd
>consider using "do" a bad program design.
>
>Tom
Thank you, indeed, if I use do(), it works good. I'll read perlfunc.
_________________________________________________________________
Direct antwoord op je vragen: gebruik MSN Messenger http://messenger.msn.nl/
Re: Declaring variables in a required script
Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
You should learn how perl works. I suppose you are running the script as
an Apache::Reqistry but you miss the version.
You problem is that if en.pl is loaded using require in a process is
will not be reloaded once more hence you lines of code won't be run.
If you really want to run the "required" code everytime you are loading
it you have to use "do" see perlfunc for more information. Still I'd
consider using "do" a bad program design.
Tom
x x schrieb:
| I'm sorry if this question has already been answered, but I couldn't
| find the answer.
|
| Here is my problem. I have a script that looks like this:
| #!/usr/local/bin/perl -Tw
|
| use strict;
| use CGI;
|
| my $q = new CGI;
|
| my $var = $q->param("var");
| $var =~ m/(.*)/; #just to don't get any tainted errors, don't use in
| public.
| $var = $1;#just to don't get any tainted errors, don't use in public.
|
| require "/Library/WebServer/mod_perl/$var.pl";
|
| print "Content-Type: text/plain\n\n";
|
| print "1\n" if $lang::varl eq $var;
| print "$var\n";
| print "$lang::varl\n";
|
|
|
| And I have the script nl.pl:
| #!/usr/bin/perl -wT
|
| use strict;
|
| $lang::varl = "nl";
|
|
|
| And the last one, en.pl:
| #!/usr/bin/perl -wT
|
| use strict;
|
| $lang::varl = "en";
|
|
| So if I make a request a few times with &var=en and then switch to
| &var=nl It sometimes happens that I get:
| nl
| en
|
| So I don't get the 1 ($lang::varl and $var don't eq) and indeed the two
| lines don't match ("en\nnl" or also sometimes "nl\nen") $var always has
| the right value, the problem is that $lang::varl doesn't always have the
| right value.
|
| I am using Apache 1.3.33, mod_perl 1.29 and Mac OS X 10.4.1.
|
| I hope someone could help me. Thank you very much!
|
| Bram.
|
| _________________________________________________________________
| Direct antwoord op je vragen: gebruik MSN Messenger
| http://messenger.msn.nl/
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCwPoLkVPeOFLgZFIRAuKDAKCFGY5qJZmdK7onl+AaD9icsPYH8gCgsTjw
fmldKQYXB1yBvh6s/7INRjw=
=Y1qX
-----END PGP SIGNATURE-----
RE: Declaring variables in a required script
Posted by Bram x <sc...@hotmail.com>.
>From: "Frank Maas" <fr...@cheiron-it.nl>
>
>Bram,
>
>It looks very much as if you are not using mod_perl. Your code does not
>contain handlers gives that away. So your problem is most likely not
>going to be solved on this list. If you are really using mod_perl (and
>not only using a mod_perl enabled httpd), please send us the configuration
>file.
>
>Regards,
>
>Frank
>
Thank you for replying. I'm sure I am using mod_perl. This is a part of my
httpd.conf file:
PerlRequire /Users/bram/Public/startup.pl
PerlTaintCheck On
PerlWarn On
Alias /mod_perl/ /Library/WebServer/mod_perl/
<Location /mod_perl>
SetHandler perl-script
PerlSendheader On
PerlHandler Apache::Registry
Options ExecCGI
</Location>
I am using perl 5.8.6.
_________________________________________________________________
Nieuw: Beeld en geluid met MSN Messenger 7.0 http://messenger.msn.nl/
RE: Declaring variables in a required script
Posted by Frank Maas <fr...@cheiron-it.nl>.
Bram,
> I'm sorry if this question has already been answered, but I couldn't
> find the answer.
It looks very much as if you are not using mod_perl. Your code does not
contain handlers gives that away. So your problem is most likely not
going to be solved on this list. If you are really using mod_perl (and
not only using a mod_perl enabled httpd), please send us the configuration
file.
Regards,
Frank